Skip to content

Fix heap OOB read in STL decoder from missing buffer bounds checks#1203

Open
gn00295120 wants to merge 1 commit into
google:mainfrom
gn00295120:fix/stl-oob-read
Open

Fix heap OOB read in STL decoder from missing buffer bounds checks#1203
gn00295120 wants to merge 1 commit into
google:mainfrom
gn00295120:fix/stl-oob-read

Conversation

@gn00295120

Copy link
Copy Markdown

Summary

StlDecoder::DecodeFromBuffer reads an 80-byte header, a 4-byte face count, and 50 bytes per face from the input buffer without checking that the buffer is large enough. A truncated or malicious STL file triggers a heap-buffer-overflow read.

Changes

  • Reject inputs smaller than 84 bytes (80-byte header + 4-byte count) before any read
  • Check the Decode() return value for the face count (was silently ignored)
  • Validate face_count against remaining_size() / 50 before entering the parse loop
  • Check per-face Decode() return values inside the loop

Reproduction

# Build with ASAN
cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
  -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" .
cmake --build build

# 1-byte STL file triggers heap-buffer-overflow READ of size 4
printf 'x' > crash.stl
./build/draco_encoder -i crash.stl

ASAN trace (before fix):

==PID==ERROR: AddressSanitizer: heap-buffer-overflow on address ...
READ of size 4 at ... thread T0
    #0 in draco::DecoderBuffer::Decode(void*, unsigned long) decoder_buffer.h:80
    #1 in draco::StlDecoder::DecodeFromBuffer stl_decoder.cc:46

StlDecoder::DecodeFromBuffer reads header bytes, face count, and
per-face data without verifying the buffer is large enough. A
truncated STL file causes a heap-buffer-overflow read.

- Require at least 84 bytes before reading header + face count
- Check Decode() return values instead of ignoring them
- Validate face_count against remaining buffer before the parse loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant