Closed ScanMountGoat closed 3 years ago
This applies to SsbhArray and SsbhByteBuffer. https://github.com/ultimate-research/ssbh_lib/blob/4a1cc5a14e7771b08b139fe0f6891e3cb49b38fd/ssbh_lib/src/lib.rs#L331-L344
This isn't possible to fix completely, but the current measures will reject negative integers without noticeably impacting performance.
Attempting to parse an offset of 16 and length of u64::MAX will first attempt to allocate an enormous vector and then seek by 16 and start filling the vector. This will panic when the allocation fails.
In practice, it's more common that the file itself is small, but the array length is malformed. In this case, the vector shouldn't be allocated up front. If less than the array's length many elements can be read, the read method should return an error. This could be achieved by only reserving up to N elements of capacity.