ws-arch2: archive/arj (methods 0-4 via codecs/compress/Lzh, CRC-32 checks; read)
This commit is contained in:
1 parent
572cd42f8a
commit
70cc54f7c8
5 files changed
+333
No files matched your search
@@ -0,0 +1,58 @@
|
||||
-- archive/arj tests: archives by ARJ 3.10 with methods 0 .. 4 (stored, the LHA-style Huffman methods 1 .. 3, method
|
||||
-- 4) give the files `arj x` extracts (names, sizes, data CRCs); header and data CRC errors, truncation; the fuzz
|
||||
-- pass. Fixtures: tools/fixtures/arj.py.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Arj = require("@formats/archive/arj")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Err = require("@formats/core/Err")
|
||||
local E = require("@tests/archive/_entries")
|
||||
local Fx = require("@tests/gen/arj")
|
||||
|
||||
local t = T.suite("arj")
|
||||
t:eq(Arj.name, "arj", "name")
|
||||
|
||||
local samples = {}
|
||||
for _, c in Fx.cases do
|
||||
local a, err = Arj.decode(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(a, c.name .. ": " .. tostring(err))
|
||||
if a then
|
||||
E.check(t, a, c.entries, c.name, false)
|
||||
end
|
||||
t:eq(F.detect(c.data), "arj", c.name .. ": detect")
|
||||
table.insert(samples, string.sub(c.data, 1, 3000))
|
||||
end
|
||||
|
||||
-- errors
|
||||
local data = Fx.cases[2].data -- -m1
|
||||
local function code(s: string): string?
|
||||
local _, e = Arj.decode(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
local hdr = string.sub(data, 1, 10) .. string.char((string.byte(data, 11) + 1) % 256) .. string.sub(data, 12)
|
||||
t:eq(code(hdr), Err.CHECKSUM, "main header CRC")
|
||||
t:eq(code(string.sub(data, 1, #data // 2)), Err.TRUNCATED, "cut")
|
||||
t:eq(code("\96\234\30\0"), Err.TRUNCATED, "short header")
|
||||
t:eq(code("PK\3\4xxxx"), Err.CORRUPT, "not arj")
|
||||
local mid = #data // 2 + 1000
|
||||
local bad = Arj.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, mid - 1) .. string.char(bit32.bxor(string.byte(data, mid), 0x10)) .. string.sub(data, mid + 1)))) :: any
|
||||
local failed = 0
|
||||
for _, e in bad:list() do
|
||||
local b, err = bad:read(e.name)
|
||||
if not b then
|
||||
failed += 1
|
||||
t:check(err.code == Err.CHECKSUM or err.code == Err.CORRUPT, "flipped data: " .. tostring(err))
|
||||
end
|
||||
end
|
||||
t:eq(failed, 1, "one entry fails after a flipped data byte")
|
||||
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
local r = Arj.decode(Bytes.reader(b))
|
||||
if r then
|
||||
for _, e in r:list() do
|
||||
r:read(e.name)
|
||||
end
|
||||
end
|
||||
return r
|
||||
end, samples, { mutations = 6 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user