From 582776aeef943039149cfc6fe962dfd623d96976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 27 Mar 2023 15:01:52 +0200 Subject: [PATCH] Trade: additional sanity assertions for {Mesh,Scene}Data bounds checks. --- src/Magnum/Trade/MeshData.cpp | 6 ++++++ src/Magnum/Trade/SceneData.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index 0695b8856..39d3f01b1 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -153,6 +153,9 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array&& inde begin += signedSize; else 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 read the `pointer` union member through `offset`. */ begin += reinterpret_cast(_indices); @@ -197,6 +200,9 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array&& inde begin += signedSize; else 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 read the `pointer` union member through `offset`. */ begin += attribute._data.offset; diff --git a/src/Magnum/Trade/SceneData.cpp b/src/Magnum/Trade/SceneData.cpp index b0b566329..2bea649bb 100644 --- a/src/Magnum/Trade/SceneData.cpp +++ b/src/Magnum/Trade/SceneData.cpp @@ -867,6 +867,10 @@ SceneData::SceneData(const SceneMappingType mappingType, const UnsignedLong mapp fieldBegin += signedFieldSize; else 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, end up */ if(isBitField) {