|
| 1 | +///| |
| 2 | +test "security/gzip - empty input" { |
| 3 | + let empty : FixedArray[Byte] = [] |
| 4 | + let result = try? gunzip_sync(empty) |
| 5 | + assert_true(result is Err(_)) |
| 6 | +} |
| 7 | + |
| 8 | +///| |
| 9 | +test "security/gzip - too short input" { |
| 10 | + let short : FixedArray[Byte] = [b'\x1F', b'\x8B'] |
| 11 | + let result = try? gunzip_sync(short) |
| 12 | + assert_true(result is Err(_)) |
| 13 | +} |
| 14 | + |
| 15 | +///| |
| 16 | +test "security/gzip - 9 bytes input" { |
| 17 | + let short : FixedArray[Byte] = [ |
| 18 | + b'\x1F', b'\x8B', b'\x08', b'\x00', b'\x00', b'\x00', b'\x00', b'\x00', |
| 19 | + b'\x00', |
| 20 | + ] |
| 21 | + let result = try? gunzip_sync(short) |
| 22 | + assert_true(result is Err(_)) |
| 23 | +} |
| 24 | + |
| 25 | +///| |
| 26 | +test "security/gzip - FNAME flag but truncated" { |
| 27 | + // GZIP header with FNAME flag (0x08) set but no actual filename data |
| 28 | + let truncated : FixedArray[Byte] = [ |
| 29 | + b'\x1F', b'\x8B', b'\x08', b'\x08', b'\x00', b'\x00', b'\x00', b'\x00', |
| 30 | + b'\x00', b'\x03', |
| 31 | + ] |
| 32 | + let result = try? gunzip_sync(truncated) |
| 33 | + assert_true(result is Err(_)) |
| 34 | +} |
| 35 | + |
| 36 | +///| |
| 37 | +test "security/zlib - empty input" { |
| 38 | + let empty : FixedArray[Byte] = [] |
| 39 | + let result = try? unzlib_sync(empty) |
| 40 | + assert_true(result is Err(_)) |
| 41 | +} |
| 42 | + |
| 43 | +///| |
| 44 | +test "security/zlib - 1 byte input" { |
| 45 | + let short : FixedArray[Byte] = [b'\x78'] |
| 46 | + let result = try? unzlib_sync(short) |
| 47 | + assert_true(result is Err(_)) |
| 48 | +} |
| 49 | + |
| 50 | +///| |
| 51 | +test "security/zlib - header only (no compressed data)" { |
| 52 | + // Valid zlib header (0x78 0x9C) but no compressed data or checksum |
| 53 | + let short : FixedArray[Byte] = [b'\x78', b'\x9C'] |
| 54 | + let result = try? unzlib_sync(short) |
| 55 | + assert_true(result is Err(_)) |
| 56 | +} |
| 57 | + |
| 58 | +///| |
| 59 | +test "security/zip - empty input" { |
| 60 | + let empty : FixedArray[Byte] = [] |
| 61 | + let result = try? unzip_sync(empty) |
| 62 | + assert_true(result is Err(_)) |
| 63 | +} |
| 64 | + |
| 65 | +///| |
| 66 | +test "security/zip - too short input" { |
| 67 | + let short : FixedArray[Byte] = [b'\x50', b'\x4B', b'\x05', b'\x06'] |
| 68 | + let result = try? unzip_sync(short) |
| 69 | + assert_true(result is Err(_)) |
| 70 | +} |
| 71 | + |
| 72 | +///| |
| 73 | +test "security/zip - unzip_list empty input" { |
| 74 | + let empty : FixedArray[Byte] = [] |
| 75 | + let result = try? unzip_list(empty) |
| 76 | + assert_true(result is Err(_)) |
| 77 | +} |
| 78 | + |
| 79 | +///| |
| 80 | +test "security/zip - path traversal detection" { |
| 81 | + // Test the is_unsafe_path function directly |
| 82 | + assert_true(is_unsafe_path("../etc/passwd")) |
| 83 | + assert_true(is_unsafe_path("foo/../../../etc/passwd")) |
| 84 | + assert_true(is_unsafe_path("..\\windows\\system32")) |
| 85 | + assert_true(is_unsafe_path("/etc/passwd")) |
| 86 | + assert_true(is_unsafe_path("\\windows\\system32")) |
| 87 | + assert_true(is_unsafe_path("C:\\windows\\system32")) |
| 88 | + assert_true(is_unsafe_path("c:/windows/system32")) |
| 89 | + assert_true(is_unsafe_path("..")) |
| 90 | + assert_true(is_unsafe_path("foo/..")) |
| 91 | + assert_true(is_unsafe_path("foo\\..")) |
| 92 | + // Safe paths |
| 93 | + assert_eq(is_unsafe_path("file.txt"), false) |
| 94 | + assert_eq(is_unsafe_path("dir/file.txt"), false) |
| 95 | + assert_eq(is_unsafe_path("dir/subdir/file.txt"), false) |
| 96 | + assert_eq(is_unsafe_path("..hidden"), false) |
| 97 | + assert_eq(is_unsafe_path("dir/..hidden/file.txt"), false) |
| 98 | + assert_eq(is_unsafe_path(""), false) |
| 99 | +} |
| 100 | + |
| 101 | +///| |
| 102 | +test "security/decompress - 2 byte input no crash" { |
| 103 | + // decompress_sync with exactly 2 bytes should not crash |
| 104 | + // (previously accessed data[2] with only length >= 2 check) |
| 105 | + let data : FixedArray[Byte] = [b'\x00', b'\x00'] |
| 106 | + let result = try? decompress_sync(data) |
| 107 | + // It's OK if this errors, just shouldn't crash with out-of-bounds |
| 108 | + let _ = result |
| 109 | +} |
| 110 | + |
| 111 | +///| |
| 112 | +test "security/decompress - 1 byte input" { |
| 113 | + let data : FixedArray[Byte] = [b'\x00'] |
| 114 | + let result = try? decompress_sync(data) |
| 115 | + let _ = result |
| 116 | +} |
| 117 | + |
| 118 | +///| |
| 119 | +test "security/decompress - empty input" { |
| 120 | + let data : FixedArray[Byte] = [] |
| 121 | + let result = try? decompress_sync(data) |
| 122 | + let _ = result |
| 123 | +} |
0 commit comments