Integer overflow in gltfio DracoCache.cpp and AssetLoader.cpp leads to heap buffer overflow
Bug Description
There are integer overflow vulnerabilities in libs/gltfio/src/DracoCache.cpp and libs/gltfio/src/AssetLoader.cpp that lead to heap buffer overflows when processing crafted GLB files with KHR_draco_mesh_compression.
DracoCache.cpp — convertAttribs() (line 100)
const uint32_t size = target->stride * n;n comes from mesh->num_points() (Draco bitstream, attacker-controlled). With stride=12 (VEC3 float) and n=357,913,942, the product 0x1_0000_0008 truncates to 8 in uint32_t. malloc(8) is called, then ConvertValue writes 4.3 GB past the buffer.
The FILAMENT_CHECK_PRECONDITION checks on lines 97-98 validate stride/component layout but do NOT validate the point count n.
DracoCache.cpp — convertFaces() (line 79)
Same overflow class in mesh->num_faces() * 3 * sizeof(T).
AssetLoader.cpp — createPrimitive() (line 1325)
const uint32_t requiredSize = sizeof(ubyte4) * vertexCount;vertexCount from accessor->count (attacker-controlled). Trigger: vertexCount = 1,073,741,825 causes requiredSize = 4.
Impact
Any application using gltfio to load untrusted GLB files is affected: Android apps via the com.google.android.filament:gltfio-android Maven artifact, desktop apps, ARCore/Sceneform apps. The code runs in the application process (non-sandboxed).
Proposed Fix
Widen multiplication to uint64_t and check for overflow before allocating. I submitted a PR at #10494 with the complete diff, but it was auto-closed since libs/gltfio is restricted to maintainers.
DracoCache.cpp convertAttribs() — before:
const uint32_t size = target->stride * n;After:
const uint64_t size64 = static_cast<uint64_t>(target->stride) * n;
if (size64 > std::numeric_limits<uint32_t>::max()) {
slog.e << "Draco vertex buffer size overflow: " << size64 << io::endl;
return;
}
const uint32_t size = static_cast<uint32_t>(size64);DracoCache.cpp convertFaces() — before:
const cgltf_size size = mesh->num_faces() * 3 * sizeof(T);After:
const uint64_t size64 = static_cast<uint64_t>(mesh->num_faces()) * 3 * sizeof(T);
if (size64 > std::numeric_limits<cgltf_size>::max()) {
slog.e << "Draco face buffer size overflow: " << size64 << io::endl;
return;
}
const cgltf_size size = static_cast<cgltf_size>(size64);AssetLoader.cpp createPrimitive() — before:
const uint32_t requiredSize = sizeof(ubyte4) * vertexCount;After:
const uint64_t requiredSize64 = static_cast<uint64_t>(sizeof(ubyte4)) * vertexCount;
if (requiredSize64 > std::numeric_limits<uint32_t>::max()) {
slog.e << "Dummy buffer size overflow: " << requiredSize64 << io::endl;
return false;
}
const uint32_t requiredSize = static_cast<uint32_t>(requiredSize64);Add #include <limits> to both files.
The full diff is available in #10494.
Source: google/filament