Skip to content

Fix panic on folders with zero data blocks#38

Open
ozzieba wants to merge 1 commit intomdsteele:masterfrom
ozzieba:fix-empty-data-blocks-panic
Open

Fix panic on folders with zero data blocks#38
ozzieba wants to merge 1 commit intomdsteele:masterfrom
ozzieba:fix-empty-data-blocks-panic

Conversation

@ozzieba
Copy link
Copy Markdown

@ozzieba ozzieba commented Feb 26, 2026

Summary

Fixes #37 -- FolderReader::seek_to_uncompressed_offset panics with "index out of bounds" when a malformed CAB file has a folder with num_data_blocks == 0 but file entries that reference it with a non-zero uncompressed offset.

Changes:

  • Add a bounds check before accessing self.data_blocks[self.current_block_index]: if data_blocks is empty, return io::Error(InvalidData) instead of panicking
  • Add a bounds check after incrementing self.current_block_index in the seek loop: if the index exceeds num_data_blocks, return io::Error(InvalidData) instead of potentially panicking on subsequent iterations
  • Add a test with a crafted malformed CAB binary (zero data blocks, non-zero file offset) that verifies the error is returned correctly

Files changed:

  • src/folder.rs -- two bounds checks in seek_to_uncompressed_offset
  • src/cabinet.rs -- one new test

All existing tests continue to pass.

Add bounds checks in FolderReader::seek_to_uncompressed_offset to
return io::Error(InvalidData) instead of panicking with index out of
bounds when a malformed CAB file has a folder with zero data blocks.

Fixes mdsteele#37

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mdsteele
Copy link
Copy Markdown
Owner

Thanks, and sorry for the slow reply. The linter is complaining, but looks good otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: index out of bounds in FolderReader::seek_to_uncompressed_offset with 0 data blocks

2 participants