usdc: return errors instead of aborting on damaged crate files - #138
Merged
Merged
Conversation
A damaged or hostile .usdc could make the crate reader allocate whatever a count in the file asked for (a few bytes of input requested exabytes), index past tables, reach todo!() for old versions, or overflow while sizing buffers. Each of these aborts an application that builds with panic = "abort", and a failed allocation aborts any application. Counts are now checked against the file length, LZ4 output is capped at its maximum expansion of the compressed input and at 4 GiB, vectors are read before they are allocated, preallocation from file counts is capped, table lookups and slicing are checked, unsupported old versions return an error, and data-dependent debug assertions are errors in every build. tests/usdc_malformed.rs mutates five fixtures deterministically and decodes every field; before this change it aborted the test process.
humships
force-pushed
the
usdc-hardening
branch
from
September 30, 2026 15:15
54e4bd0 to
34c5f41
Compare
humships
pushed a commit
to raspao-studio/openusd
that referenced
this pull request
Sep 30, 2026
Brings this v0.7.0 branch to the change offered upstream in mxpv#138 (formatting, a 4 GiB cap on one LZ4-decompressed block, and tests/usdc_malformed.rs).
Owner
|
Thanks! |
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.
While adding USD import to a macOS app that builds with
panic = "abort", we fuzzed the usdc reader with mutated copies of valid files. Several inputs crash the process instead of returning an error:read_compressed(compressed_sizeandestimated_count), the paths table,read_vec. One example:memory allocation of 7341785157331845235 bytes failedtodo!()for pre-0.4 crate versions and for chunked LZ4decode_ints, and integer overflow inencoded_buffer_sizedebug_assert!s, which panic in debug builds and pass silently in releaseChanges, in
usdc/reader.rsandusdc/coding.rsonly:read_vecreads the bytes before allocating the vectordecode_intsslice are checkedtodo!()paths returnReadError::unsupportedcorrupt!errorsencoded_buffer_sizeuses saturating arithmetictests/usdc_malformed.rsmutates five fixtures deterministically (2,000 rounds each;OPENUSD_USDC_MUTATIONSraises it) and decodes every field. Onmainit aborts with an allocation failure; with this change it passes. The CI commands fromci.ymlpass locally (check, clippy with all features, fmt, doc, and the full test suite withvendor/usd-wg-assetsinitialized). It is one commit, written as a release-notes entry per CONTRIBUTING.md.Downstream, about a million mutations of Blender- and Apple-authored usdc and usdz files went through a
Stagewithout a crash.Happy to split this up or change the approach.