Files
rosetta/tests/archive/zoo.luau
T
4DBug f1c2c6ed06 ws-arch2: archive/zoo (types 1 / 2, stored / LZW / lzh, CRC-16; read) and codecs/compress/Lzw 'zoo' variant (13-bit codes)
codecs/compress/Lzw: decode accepts variant "zoo" (gif layout, 8-bit symbols, up to 13-bit codes; its tables grow
to 8192 entries); gif / tiff behaviour unchanged.
2026-10-31 14:49:54 -05:00

59 lines
2.1 KiB
Luau

-- archive/zoo tests: zoo archives assembled by tools/fixtures/zoo.py (type 1 / type 2 entries, long and directory
-- names, a deleted entry, methods stored / LZW / lzh, an LZW stream with table resets) give the files The Unarchiver
-- extracts (names, sizes, data CRCs); CRC errors; the fuzz pass. Fixtures: tools/fixtures/zoo.py.
local T = require("@tests/T")
local F = require("@formats")
local Zoo = require("@formats/archive/zoo")
local Bytes = require("@formats/core/Bytes")
local Err = require("@formats/core/Err")
local E = require("@tests/archive/_entries")
local Fx = require("@tests/gen/zoo")
local t = T.suite("zoo")
t:eq(Zoo.name, "zoo", "name")
local samples = {}
for _, c in Fx.cases do
local a, err = Zoo.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)
t:eq(a._byName["gone.txt"], nil, c.name .. ": deleted entry skipped")
end
t:eq(F.detect(c.data), "zoo", c.name .. ": detect")
if #c.data < 60000 then
table.insert(samples, c.data)
end
end
local data = Fx.cases[2].data -- lzw
local function code(s: string): string?
local _, e = Zoo.decode(Bytes.reader(buffer.fromstring(s)))
return e and e.code
end
t:eq(code(string.sub(data, 1, 20)), Err.TRUNCATED, "short header")
t:eq(code(string.rep("\0", 100)), Err.CORRUPT, "no tag")
t:eq(code(string.sub(data, 1, 200)), Err.TRUNCATED, "cut")
local mid = #data // 2
local bad = Zoo.decode(Bytes.reader(buffer.fromstring(string.sub(data, 1, mid - 1) .. string.char(bit32.bxor(string.byte(data, mid), 4)) .. 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 or err.code == Err.TRUNCATED, "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 = Zoo.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()