ESM4 reader incorrectly subtracts 4 bytes from decompressed data size

Line 541 of ESM4 reader.cpp incorrectly subtracts 4 bytes (sizeof(uncompressedSize), a std::uint32_t) from the decompressed data size: https://gitlab.com/OpenMW/openmw/-/blob/4e718b500ffee6657db90297d7b8a08a57d439bc/components/esm4/reader.cpp#L541.

This dates back to cc9cii's initial implementation: ba3ae448.

The issue came up while analyzing ESM4 parsing across games. Example below is from a modified ESP, but it applies to every normal ESM4 content file with compressed data and certain small subrecords:

24-byte header: image

26-byte data size: image

26 bytes ends right at the next subrecord: image

Data size is used in getSubRecordHeader() to check if the remaining bytes can hold another subrecord. In this case, subtracting 4 from data size would skip the FNAM subrecord: image

image

image

ESM4UncompressedFNAM.esp

ESM4CompressedFNAM.esp

Steps to Reproduce

  1. Launch OpenMW with ESM4CompressedFNAM.esp (it's modified to only have Morrowind.esm as a master).
  2. Pause the debugger on line 541 and verify sizes against the uncompressed file.
  3. When the line 541 breakpoint hits, pause on line 581 and observe the check fails at mCtx.recordRead = 18.