Browse Source

Trade: additional sanity assertions for {Mesh,Scene}Data bounds checks.

pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
582776aeef
  1. 6
      src/Magnum/Trade/MeshData.cpp
  2. 4
      src/Magnum/Trade/SceneData.cpp

6
src/Magnum/Trade/MeshData.cpp

@ -153,6 +153,9 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array<char>&& inde
begin += signedSize; begin += signedSize;
else else
end += signedSize; end += signedSize;
/* This would blow up if some of the above calculations are not ready
for 64-bit sizes */
CORRADE_INTERNAL_ASSERT(end >= begin);
/* Add the base data offset to both begin and end. Yes, yes, this may /* Add the base data offset to both begin and end. Yes, yes, this may
read the `pointer` union member through `offset`. */ read the `pointer` union member through `offset`. */
begin += reinterpret_cast<std::size_t>(_indices); begin += reinterpret_cast<std::size_t>(_indices);
@ -197,6 +200,9 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array<char>&& inde
begin += signedSize; begin += signedSize;
else else
end += signedSize; end += signedSize;
/* This would blow up if some of the above calculations are not
ready for 64-bit sizes */
CORRADE_INTERNAL_ASSERT(end >= begin);
/* Add the base data offset to both begin and end. Yes, yes, this /* Add the base data offset to both begin and end. Yes, yes, this
may read the `pointer` union member through `offset`. */ may read the `pointer` union member through `offset`. */
begin += attribute._data.offset; begin += attribute._data.offset;

4
src/Magnum/Trade/SceneData.cpp

@ -867,6 +867,10 @@ SceneData::SceneData(const SceneMappingType mappingType, const UnsignedLong mapp
fieldBegin += signedFieldSize; fieldBegin += signedFieldSize;
else else
fieldEnd += signedFieldSize; fieldEnd += signedFieldSize;
/* This would blow up if some of the above calculations are not
ready for 64-bit sizes */
CORRADE_INTERNAL_ASSERT(mappingEnd >= mappingBegin);
CORRADE_INTERNAL_ASSERT(fieldEnd >= fieldBegin);
/* For bit fields round the offset to whole bytes -- begin down, /* For bit fields round the offset to whole bytes -- begin down,
end up */ end up */
if(isBitField) { if(isBitField) {

Loading…
Cancel
Save