formats: reject truncated SWF movie headers in gfx::Movie::parse #45

Merged
ahmetbagci8 merged 1 commit from upstream-pr/45 into dev 2026-11-29 20:55:45 +00:00
ahmetbagci8 commented 2026-11-29 20:43:17 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T20:43:17Z.


Problem

In crates/victory-formats/src/gfx.rs, Movie::parse computes irst = 8 + (5 + 4 * field_bits).div_ceil(8) + 4 and passes irst..bytes.len() to ags() without checking irst <= bytes.len(). When a header is truncated ( irst > bytes.len()), ags() exits its while at < range.end loop immediately and returns Some(vec![]), so Movie::parse succeeds with self.first > self.bytes.len() and subsequent
eplace_shapes fails on self.bytes.get(..self.first)?.

Fix

Return None from Movie::parse when irst > bytes.len(), and add unit test runcated_movie_header_is_refused.

Verification

  • cargo test -p victory-formats --lib gfx::tests (19 passed, 0 failed)
  • cargo clippy -p victory-formats --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5554916707 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/45). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T20:43:17Z. --- ## Problem In crates/victory-formats/src/gfx.rs, Movie::parse computes irst = 8 + (5 + 4 * field_bits).div_ceil(8) + 4 and passes irst..bytes.len() to ags() without checking irst <= bytes.len(). When a header is truncated ( irst > bytes.len()), ags() exits its while at < range.end loop immediately and returns Some(vec![]), so Movie::parse succeeds with self.first > self.bytes.len() and subsequent eplace_shapes fails on self.bytes.get(..self.first)?. ## Fix Return None from Movie::parse when irst > bytes.len(), and add unit test runcated_movie_header_is_refused. ## Verification - cargo test -p victory-formats --lib gfx::tests (19 passed, 0 failed) - cargo clippy -p victory-formats --tests (0 warnings)
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!45
No description provided.