ws-arch2-cab: codecs/compress/Lzx (CAB LZX: windows 2^15..2^21, verbatim / aligned / uncompressed blocks, delta-coded trees, R0..R2, E8 translation, 32 KB frames; written from the spec) + cab LZX folders, checked against cabextract on cabinets of a fixture LZX compressor (tools/fixtures/_lzx.py) and libmspack's samples; Deflate.mszip (generic MSZIP blocks: CK + deflate, dictionary carried across blocks; for cab and later model/x); cab bench lines
This commit is contained in:
1 parent
825c45b03c
commit
c54c8daff5
9 files changed
+990
-49
No files matched your search
+33
-3
@@ -2,7 +2,9 @@
|
||||
-- their dictionary (several folders, reserve areas, attributes, UTF-8 names) and libmspack's test cabinets give the
|
||||
-- files cabextract extracts (names, sizes, data CRCs, DOS times read as UTC); cabextract / gcab / 7z extract our
|
||||
-- writer's output (fixture step) and it round-trips; spanned files are UNSUPPORTED; checksum, truncation and
|
||||
-- signature errors; Deflate's preset dictionary; the fuzz pass. Fixtures: tools/fixtures/cab.py.
|
||||
-- signature errors, libmspack's broken cabinets; LZX (codecs/compress/Lzx) from a fixture compressor whose cabinets
|
||||
-- cabextract extracts (windows 2^15 .. 2^21, verbatim / aligned / uncompressed blocks, E8); Deflate's preset
|
||||
-- dictionary; the fuzz pass. Fixtures: tools/fixtures/cab.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Cab = require("@formats/archive/cab")
|
||||
@@ -33,7 +35,7 @@ for _, c in Fx.cases do
|
||||
t:eq(F.detect(c.data), "cab", c.name .. ": detect")
|
||||
table.insert(samples, string.sub(c.data, 1, 4000))
|
||||
end
|
||||
t:check(methods.store and methods.mszip, "covers store and mszip")
|
||||
t:check(methods.store and methods.mszip and methods.lzx, "covers store, mszip and lzx")
|
||||
|
||||
-- attributes, UTF-8 names, reserve areas (the builder's two-folder cabinet)
|
||||
local two = assert(load(Fx.cases[5].data))
|
||||
@@ -74,7 +76,35 @@ for _, c in Fx.spanned do
|
||||
end
|
||||
end
|
||||
|
||||
-- Deflate's preset dictionary
|
||||
-- libmspack's broken cabinets (cabextract fails on every one): an error (never a throw), not a full read
|
||||
for _, c in Fx.bad do
|
||||
local a = load(c.data)
|
||||
local ok = a ~= nil
|
||||
if a then
|
||||
for _, e in a:list() do
|
||||
if not a:read(e.name) then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
end
|
||||
-- a 263-byte file name: over the format's 256-byte limit, which libmspack enforces and we do not
|
||||
t:check(not ok or c.name == "cve-2017-11423-fname-overread.cab", c.name .. ": fails")
|
||||
table.insert(samples, c.data)
|
||||
end
|
||||
|
||||
-- LZX directly
|
||||
local Lzx = require("@formats/codecs/compress/Lzx")
|
||||
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 14), "LZX window 2^14 unsupported")
|
||||
t:check(not Lzx.decode(buffer.create(10), 0, 10, 100, 16), "LZX of zeros")
|
||||
t:check(not Lzx.decode(buffer.create(10), 4, 10, 100, 16), "LZX range past the end")
|
||||
|
||||
-- Deflate's preset dictionary and MSZIP blocks
|
||||
local block1 = assert(Deflate.compress(string.rep("ab", 50)))
|
||||
local mszip = buffer.create(buffer.len(block1) + 2)
|
||||
buffer.writestring(mszip, 0, "CK")
|
||||
buffer.copy(mszip, 2, block1)
|
||||
t:eq(buffer.tostring(assert(Deflate.mszip(mszip, { { offset = 0, length = buffer.len(mszip), size = 100 } }))), string.rep("ab", 50), "Deflate.mszip")
|
||||
t:eq(select(2, Deflate.mszip(mszip, { { offset = 1, length = 4, size = 100 } })).code, Err.CORRUPT, "Deflate.mszip without CK")
|
||||
local dictText = string.rep("abcdefgh", 100)
|
||||
local z = assert(Deflate.compress(dictText .. dictText))
|
||||
local plain = assert(Deflate.inflate(z, nil, nil, 1600, buffer.fromstring("unused prefix")))
|
||||
|
||||
Reference in new issue
Block a user