| ... | @@ -22,7 +22,7 @@ fn isSkippableMagic(magic: u32) bool { | ... | @@ -22,7 +22,7 @@ fn isSkippableMagic(magic: u32) bool { |
| 22 | /// if the the frame is skippable, `null` for Zstanndard frames that do not | 22 | /// if the the frame is skippable, `null` for Zstanndard frames that do not |
| 23 | /// declare their content size. Returns `UnusedBitSet` and `ReservedBitSet` | 23 | /// declare their content size. Returns `UnusedBitSet` and `ReservedBitSet` |
| 24 | /// errors if the respective bits of the the frame descriptor are set. | 24 | /// errors if the respective bits of the the frame descriptor are set. |
| 25 | pub fn getFrameDecompressedSize(src: []const u8) !?usize { | 25 | pub fn getFrameDecompressedSize(src: []const u8) !?u64 { |
| 26 | switch (try frameType(src)) { | 26 | switch (try frameType(src)) { |
| 27 | .zstandard => { | 27 | .zstandard => { |
| 28 | const header = try decodeZStandardHeader(src[4..], null); | 28 | const header = try decodeZStandardHeader(src[4..], null); |
| ... | @@ -216,7 +216,7 @@ pub const DecodeState = struct { | ... | @@ -216,7 +216,7 @@ pub const DecodeState = struct { |
| 216 | ); | 216 | ); |
| 217 | @field(self, field_name).table = .{ .fse = @field(self, field_name ++ "_fse_buffer")[0..table_size] }; | 217 | @field(self, field_name).table = .{ .fse = @field(self, field_name ++ "_fse_buffer")[0..table_size] }; |
| 218 | @field(self, field_name).accuracy_log = std.math.log2_int_ceil(usize, table_size); | 218 | @field(self, field_name).accuracy_log = std.math.log2_int_ceil(usize, table_size); |
| 219 | return counting_reader.bytes_read; | 219 | return std.math.cast(usize, counting_reader.bytes_read) orelse return error.MalformedFseTable; |
| 220 | }, | 220 | }, |
| 221 | .repeat => return if (self.fse_tables_undefined) error.RepeatModeFirst else 0, | 221 | .repeat => return if (self.fse_tables_undefined) error.RepeatModeFirst else 0, |
| 222 | } | 222 | } |
| ... | @@ -571,7 +571,8 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8, | ... | @@ -571,7 +571,8 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8, |
| 571 | | 571 | |
| 572 | if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported; | 572 | if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported; |
| 573 | | 573 | |
| 574 | const window_size = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown; | 574 | const window_size_raw = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown; |
| | 575 | const window_size = std.math.cast(usize, window_size_raw) orelse return error.WindowTooLarge; |
| 575 | | 576 | |
| 576 | const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum; | 577 | const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum; |
| 577 | var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null; | 578 | var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null; |
| ... | @@ -1043,7 +1044,8 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H | ... | @@ -1043,7 +1044,8 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1043 | const table_size = try decodeFseTable(&bit_reader, 256, 6, &entries); | 1044 | const table_size = try decodeFseTable(&bit_reader, 256, 6, &entries); |
| 1044 | const accuracy_log = std.math.log2_int_ceil(usize, table_size); | 1045 | const accuracy_log = std.math.log2_int_ceil(usize, table_size); |
| 1045 | | 1046 | |
| 1046 | var huff_data = src[1 + counting_reader.bytes_read .. compressed_size + 1]; | 1047 | const start_index = std.math.cast(usize, 1 + counting_reader.bytes_read) orelse return error.MalformedHuffmanTree; |
| | 1048 | var huff_data = src[start_index .. compressed_size + 1]; |
| 1047 | var huff_bits: ReverseBitReader = undefined; | 1049 | var huff_bits: ReverseBitReader = undefined; |
| 1048 | try huff_bits.init(huff_data); | 1050 | try huff_bits.init(huff_data); |
| 1049 | | 1051 | |