fix(STLLoader): guard isBinary against buffers shorter than 84 bytes#431
Open
fursund wants to merge 1 commit into
Open
fix(STLLoader): guard isBinary against buffers shorter than 84 bytes#431fursund wants to merge 1 commit into
fursund wants to merge 1 commit into
Conversation
STLLoader.parse() calls isBinary() first, which reads a little-endian
uint32 at offset 80 via DataView.getUint32(80, true) to compute the
expected binary file size. This call is unconditional and throws
RangeError: Offset is outside the bounds of the DataView
for any STL whose total payload is shorter than 84 bytes (the binary
STL header: 80 bytes + 4-byte face count). Such files do exist in the
wild: minimal/empty ASCII solids such as
solid s
endsolid s
are only 19 bytes and crash the parser before the ASCII-vs-binary
disambiguation runs at all. A short ASCII STL is a perfectly legal STL.
Return false from isBinary() when the buffer is shorter than the
binary header so short payloads cleanly fall through to parseASCII().
The same bug exists in three.js's examples/jsm/loaders/STLLoader.js.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
STLLoader.parse()callsisBinary()first to choose between the binary and ASCII parsers.isBinary()unconditionally reads a little-endian uint32 at offset 80 viaDataView.getUint32(80, true)to compute the expected binary file size. This call is not guarded by a buffer-length check and throwsfor any STL whose total payload is shorter than 84 bytes (the binary STL header: 80 bytes + 4-byte face count).
Such files exist in the wild: minimal/empty ASCII solids such as
are only 19 bytes, and they are perfectly legal STL. Today the loader crashes on them with the RangeError above before the ASCII-vs-binary disambiguation runs at all.
Reproduction
The fix
Return
falsefromisBinary()when the buffer is shorter than the binary header (84 bytes). Short payloads then fall through toparseASCII()as they should.Notes
examples/jsm/loaders/STLLoader.js— happy to mirror this patch there as a follow-up.BufferGeometry, which is what an empty solid should produce.Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com