-- archive/arj tests against ARJ 3.10 (tools/fixtures/arj.py). local T = require("@tests/T") local F = require("@rosetta") local Arj = require("@rosetta/archive/arj") local Bytes = require("@rosetta/core/Bytes") local Err = require("@rosetta/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 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()