Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/mpk_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub fn zip_extract_truncated_archive_test() -> Nil {
Nil
}

/// Verifies out-of-range central-directory offsets fail without crashing.
pub fn zip_extract_corrupted_directory_offset_test() -> Nil {
zip.extract(corrupted_offset_zip_binary())
|> should.be_error
Nil
}

// A stored ZIP archive containing one ../evil.txt entry.
pub fn parse_widget_name_test() -> Nil {
let xml = "<widget><name>DataGrid</name></widget>"
Expand Down Expand Up @@ -297,4 +304,24 @@ fn truncated_zip_binary() -> BitArray {
0x00, 0x00,
>>
}

/// Verifies parse widget name behavior.
// A ZIP archive whose central-directory offset points beyond the buffer.

fn corrupted_offset_zip_binary() -> BitArray {
<<
0x50, 0x4b, 0x03, 0x04, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x54, 0x23,
0x5d, 0xbc, 0x6c, 0xb4, 0x4d, 0x11, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00,
0x16, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2f, 0x57, 0x69, 0x64, 0x67, 0x65, 0x74, 0x2e, 0x6d, 0x6a, 0x73,
0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c,
0x74, 0x20, 0x31, 0x0a, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x54, 0x23, 0x5d, 0xbc, 0x6c, 0xb4, 0x4d, 0x11, 0x00,
0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x63, 0x6f,
0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x57, 0x69, 0x64,
0x67, 0x65, 0x74, 0x2e, 0x6d, 0x6a, 0x73, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x44, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff,
0xff, 0x00, 0x00,
>>
}
Loading