diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2022-01-20 23:05:23 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-20 21:05:23 -0500 |
| commit | be71e26d9afc470a9293e74a6f56ca87f7412be0 (patch) | |
| tree | ebcaf100b26c91ef492bb139c0ee579f09a28c9e /ZAPD/ZCollision.cpp | |
| parent | 0ba78130478ee1272bc0e2f2fec2d162e7f7f995 (diff) | |
Fix out-of-bounds reading when converting textures to C (#236)
* Fill buffer to a multiple of 8 bytes
* Remove overloaded bitconverter methods and use boundary-checker .at method when possible
* Add a warning in oob reads in the bitconverter
* Remove repeated code
* format
* Whoops
* whoops++
Diffstat (limited to 'ZAPD/ZCollision.cpp')
| -rw-r--r-- | ZAPD/ZCollision.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp index 6554005..0b04ca5 100644 --- a/ZAPD/ZCollision.cpp +++ b/ZAPD/ZCollision.cpp @@ -256,32 +256,28 @@ size_t ZCollisionHeader::GetRawDataSize() const PolygonEntry::PolygonEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) { - const uint8_t* data = rawData.data(); - - type = BitConverter::ToUInt16BE(data, rawDataIndex + 0); - vtxA = BitConverter::ToUInt16BE(data, rawDataIndex + 2); - vtxB = BitConverter::ToUInt16BE(data, rawDataIndex + 4); - vtxC = BitConverter::ToUInt16BE(data, rawDataIndex + 6); - a = BitConverter::ToUInt16BE(data, rawDataIndex + 8); - b = BitConverter::ToUInt16BE(data, rawDataIndex + 10); - c = BitConverter::ToUInt16BE(data, rawDataIndex + 12); - d = BitConverter::ToUInt16BE(data, rawDataIndex + 14); + type = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + vtxA = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + vtxB = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + vtxC = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); + a = BitConverter::ToUInt16BE(rawData, rawDataIndex + 8); + b = BitConverter::ToUInt16BE(rawData, rawDataIndex + 10); + c = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12); + d = BitConverter::ToUInt16BE(rawData, rawDataIndex + 14); } WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) { - const uint8_t* data = rawData.data(); - - xMin = BitConverter::ToInt16BE(data, rawDataIndex + 0); - ySurface = BitConverter::ToInt16BE(data, rawDataIndex + 2); - zMin = BitConverter::ToInt16BE(data, rawDataIndex + 4); - xLength = BitConverter::ToInt16BE(data, rawDataIndex + 6); - zLength = BitConverter::ToInt16BE(data, rawDataIndex + 8); + xMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); + ySurface = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); + zMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 4); + xLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); + zLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); if (Globals::Instance->game == ZGame::OOT_SW97) - properties = BitConverter::ToInt16BE(data, rawDataIndex + 10); + properties = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); else - properties = BitConverter::ToInt32BE(data, rawDataIndex + 12); + properties = BitConverter::ToInt32BE(rawData, rawDataIndex + 12); } std::string WaterBoxHeader::GetBodySourceCode() const |
