paavohtl Claude Opus 4.6 commited on
Commit
3aa5d47
·
1 Parent(s): 0f02b41

fix: add bounds validation for frame metadata regions in parse_spr_header

Browse files

Validate that secondary frame table and main frame metadata fit within
the input slice before attempting to read them, preventing panics on
truncated .spr data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

crates/openwa-core/src/render/spr.rs CHANGED
@@ -117,6 +117,9 @@ pub fn parse_spr_header(data: &[u8]) -> Result<SprHeader, SprError> {
117
  cursor = align4(cursor + 2);
118
  secondary_frame_offset = cursor;
119
  cursor += secondary_frame_count as usize * 12;
 
 
 
120
  }
121
 
122
  // Main frame header (12 bytes)
@@ -147,6 +150,10 @@ pub fn parse_spr_header(data: &[u8]) -> Result<SprHeader, SprError> {
147
  let frame_meta_offset = align4(cursor);
148
  let bitmap_offset = frame_meta_offset + frame_count as usize * 12;
149
 
 
 
 
 
150
  let bitmap_size = if data.len() > bitmap_offset {
151
  data.len() - bitmap_offset
152
  } else {
 
117
  cursor = align4(cursor + 2);
118
  secondary_frame_offset = cursor;
119
  cursor += secondary_frame_count as usize * 12;
120
+ if data.len() < cursor {
121
+ return Err(SprError::TooShort { expected: cursor, actual: data.len() });
122
+ }
123
  }
124
 
125
  // Main frame header (12 bytes)
 
150
  let frame_meta_offset = align4(cursor);
151
  let bitmap_offset = frame_meta_offset + frame_count as usize * 12;
152
 
153
+ if data.len() < bitmap_offset {
154
+ return Err(SprError::TooShort { expected: bitmap_offset, actual: data.len() });
155
+ }
156
+
157
  let bitmap_size = if data.len() > bitmap_offset {
158
  data.len() - bitmap_offset
159
  } else {