summaryrefslogtreecommitdiff
path: root/src/factories/VtxFactory.cpp
diff options
context:
space:
mode:
authorJeod <47716344+JeodC@users.noreply.github.com>2026-07-21 07:51:22 -0400
committerLywx <kiritodev01@gmail.com>2026-07-21 10:28:15 -0600
commit6e9ee0aaffb6f338551d9fc8fd447e1fe5a03603 (patch)
tree1e7326617ccc92d5d92bebf006d614c8e094354e /src/factories/VtxFactory.cpp
parent4c8ef537bffe99e55e2087a4f938f1ddb35de815 (diff)
BK: Add romhack guards for extraction and soundfontctl factory
Diffstat (limited to 'src/factories/VtxFactory.cpp')
-rw-r--r--src/factories/VtxFactory.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/factories/VtxFactory.cpp b/src/factories/VtxFactory.cpp
index 8cb6efb..f0790ef 100644
--- a/src/factories/VtxFactory.cpp
+++ b/src/factories/VtxFactory.cpp
@@ -159,6 +159,15 @@ std::optional<std::shared_ptr<IParsedData>> VtxFactory::parse(std::vector<uint8_
auto count = GetSafeNode<size_t>(node, "count");
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
+
+ // Garbage G_VTX commands in DLs can autogen a count that overruns the file;
+ // clamp to what the segment actually holds before the reader copies it.
+ if (count * sizeof(VtxRaw) > segment.size) {
+ SPDLOG_WARN("VTX at 0x{:X}: count {} needs 0x{:X} bytes but segment holds 0x{:X}; clamping to {}",
+ GetSafeNode<uint32_t>(node, "offset"), count, count * sizeof(VtxRaw), segment.size,
+ segment.size / sizeof(VtxRaw));
+ count = segment.size / sizeof(VtxRaw);
+ }
LUS::BinaryReader reader(segment.data, count * sizeof(VtxRaw));
reader.SetEndianness(Torch::Endianness::Big);