-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix two big bugs exposed by fuzzing tests
1. Reading distance code while parsing fixed block as number insted as code. Codes has to be read MSB first, so with @bitreverse. 2. Reporting EndOfStream in bit reader by checking wrong variable. Big thanks to @squeek502 for finding this. Fixes: #8
- Loading branch information
Showing
8 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const std = @import("std"); | ||
const flate = @import("flate"); | ||
|
||
pub fn main() !void { | ||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
defer std.debug.assert(gpa.deinit() == .ok); | ||
const allocator = gpa.allocator(); | ||
|
||
// Read the data from stdin | ||
const stdin = std.io.getStdIn(); | ||
const data = try stdin.readToEndAlloc(allocator, std.math.maxInt(usize)); | ||
defer allocator.free(data); | ||
|
||
var fbs = std.io.fixedBufferStream(data); | ||
const reader = fbs.reader(); | ||
|
||
// Compress the data | ||
var buf = std.ArrayList(u8).init(allocator); | ||
defer buf.deinit(); | ||
// TODO: vary the level | ||
try flate.raw.compress(reader, buf.writer(), .default); | ||
|
||
// Now try to decompress it | ||
var buf_fbs = std.io.fixedBufferStream(buf.items); | ||
var inflate = flate.raw.decompressor(buf_fbs.reader()); | ||
const inflated = inflate.reader().readAllAlloc(allocator, std.math.maxInt(usize)) catch |err| { | ||
std.debug.print("{}\n", .{err}); | ||
return; | ||
}; | ||
defer allocator.free(inflated); | ||
|
||
std.debug.print("OK {d}\n", .{data.len}); | ||
try std.testing.expectEqualSlices(u8, data, inflated); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.