gpu: bounds-check pipeline stream subobjects before reading #37

Merged
ahmetbagci8 merged 1 commit from upstream-pr/37 into dev 2026-11-29 13:19:46 +00:00
ahmetbagci8 commented 2026-11-29 12:39:34 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T12:39:34Z.


Problem

In crates/victory-gpu/src/pipeline.rs, create_stream loops while at + 8 <= desc.size, reads the subobject kind and looks up its size, and then immediately reads a Bytecode at desc.stream.add(at + 8) and passes desc.stream.add(at) to graphics.read(kind, ...) (up to 336 bytes) without checking that size <= desc.size - at. A truncated subobject at the end of a stream causes out-of-bounds reads / UB.

Fix

Verify size <= desc.size - at (and use desc.size.saturating_sub(at) >= 8 in the loop condition plus
ead_unaligned() for Bytecode) before reading any subobject payload, breaking with a warning if truncated. Added unit test runcated_stream_subobject_is_ignored_without_reading_past_end.

Verification

  • cargo test -p victory-gpu --lib pipeline::tests (3 passed, 0 failed)
  • cargo clippy -p victory-gpu --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5550789206 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/37). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T12:39:34Z. --- ## Problem In crates/victory-gpu/src/pipeline.rs, create_stream loops while at + 8 <= desc.size, reads the subobject kind and looks up its size, and then immediately reads a Bytecode at desc.stream.add(at + 8) and passes desc.stream.add(at) to graphics.read(kind, ...) (up to 336 bytes) without checking that size <= desc.size - at. A truncated subobject at the end of a stream causes out-of-bounds reads / UB. ## Fix Verify size <= desc.size - at (and use desc.size.saturating_sub(at) >= 8 in the loop condition plus ead_unaligned() for Bytecode) before reading any subobject payload, breaking with a warning if truncated. Added unit test runcated_stream_subobject_is_ignored_without_reading_past_end. ## Verification - cargo test -p victory-gpu --lib pipeline::tests (3 passed, 0 failed) - cargo clippy -p victory-gpu --tests (0 warnings)
edsuuu commented 2026-11-29 13:19:43 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by edsuuu on 2026-11-29T13:19:43Z.

Review: APPROVED


Thanks, clean and well tested. It passed our full local CI together with the other fixes of this batch. Merged into dev, where everything is tested in the game first; it reaches main with the next release.

<!-- greyfinch-sync:edsuuu/VI-BR-PORT:review:6103046910 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/37#pullrequestreview-6103046910). Originally posted by [edsuuu](https://github.com/edsuuu) on 2026-11-29T13:19:43Z. **Review:** APPROVED --- Thanks, clean and well tested. It passed our full local CI together with the other fixes of this batch. Merged into `dev`, where everything is tested in the game first; it reaches `main` with the next release.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
edsuuu/VI-BR-PORT!37
No description provided.