ws-audio: merge ws/absorb (flac, bmp, zip)
No files matched your search
@@ -0,0 +1,268 @@
|
||||
-- archive/zip + containers/Zip tests: generated archives (comment with a fake end record, data descriptors,
|
||||
-- force_zip64, an all-ZIP64 archive, 66000 entries, a prefix stub, a wrong local header, unicode, empty) read entry by
|
||||
-- entry against Python's zipfile listing (and every Webamp demo skin when SKINS_DIR is set); lookup rules; bad CRC,
|
||||
-- encrypted and unsupported entries; the writer (stored / deflated, levels, UTF-8 names, DOS times, comments, ZIP64,
|
||||
-- raw copies) read back; the Archive API (list / read / add / remove / write, create, encode of a table) and the api;
|
||||
-- corrupt input never throws. The writer's output was also checked by hand: `unzip -t`, Python zipfile and 7z read it.
|
||||
-- Ported from zip-luau tests/zip.luau. Fixtures: tools/fixtures/zip.py.
|
||||
local T = require("@tests/T")
|
||||
local Zip = require("@formats/containers/Zip")
|
||||
local ZipF = require("@formats/archive/zip")
|
||||
local Deflate = require("@formats/codecs/Deflate")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local F = require("@formats")
|
||||
local Fx = require("@tests/gen/zip_cases")
|
||||
|
||||
local t = T.suite("zip")
|
||||
|
||||
local function dataOf(a: any): string
|
||||
if a.data then
|
||||
return a.data
|
||||
end
|
||||
return buffer.tostring(Deflate.zlib(buffer.fromstring(a.dataZ)) :: buffer)
|
||||
end
|
||||
|
||||
-- open an archive and compare it with zipfile's listing; read every entry
|
||||
local function verify(a: any, label: string): (any, number)
|
||||
local z, err = Zip.open(dataOf(a))
|
||||
t:check(z, label .. ": open: " .. tostring(err))
|
||||
local list = z:list()
|
||||
t:eq(#list, a.count, label .. ": entries")
|
||||
local bytes = 0
|
||||
for i, want in a.entries do
|
||||
local e = list[i]
|
||||
t:check(e.rawName == want[1] or e.name == string.gsub(want[1], "\\", "/"), label .. ": name " .. e.rawName)
|
||||
t:check(e.size == want[2] and e.crc32 == want[3] and e.method == want[4], label .. ": " .. e.name .. " size / crc / method")
|
||||
local data, rerr = z:read(e)
|
||||
t:check(data, label .. ": read " .. e.name .. ": " .. tostring(rerr))
|
||||
t:check(buffer.len(data :: buffer) == want[2] and Crc32.of(data :: buffer) == want[3], label .. ": " .. e.name .. " content")
|
||||
bytes += want[2]
|
||||
end
|
||||
return z, bytes
|
||||
end
|
||||
|
||||
local byName = {}
|
||||
for _, a in Fx.archives do
|
||||
byName[a.name] = a
|
||||
a.zip = verify(a, a.name)
|
||||
end
|
||||
t:note("%d generated archives match Python zipfile", #Fx.archives)
|
||||
local total, nent = 0, 0
|
||||
for _, s in Fx.skins do
|
||||
local _, bytes = verify(s, s.name)
|
||||
total += bytes
|
||||
nent += s.count
|
||||
end
|
||||
if #Fx.skins > 0 then
|
||||
t:note("%d skins, %d entries, %.2f MB read and CRC-checked", #Fx.skins, nent, total / 1e6)
|
||||
else
|
||||
t:note("(no skins: set SKINS_DIR to the Webamp demo skins)")
|
||||
end
|
||||
|
||||
-- lookup and specifics
|
||||
do
|
||||
local z = byName.basic.zip
|
||||
t:eq(z:find("readme.txt").name, "readme.txt", "find exact")
|
||||
t:eq(z:find("README.TXT").name, "readme.txt", "find case-insensitive")
|
||||
t:eq(z:find("main.bmp").name, "Skin/Main.BMP", "find by basename skips __MACOSX")
|
||||
t:eq(z:find("skin\\MAIN.bmp").name, "Skin/Main.BMP", "find with backslashes")
|
||||
t:check(z:find("__MACOSX/Skin/._Main.BMP") ~= nil, "junk still found by its full path")
|
||||
t:check(z:find("Skin/") == nil, "directories are not found")
|
||||
t:check(z:find("nope.bmp") == nil, "missing")
|
||||
t:eq(z:find("deep.txt").name, "Skin/sub/deep.txt", "basename in a deeper folder")
|
||||
t:eq(z:readString("DEEP.TXT"), "deep", "readString by name")
|
||||
t:eq(z:readString("Other/\u{fc}nicode.txt"), "h\u{e9}llo", "unicode basename")
|
||||
local u = z:find("sk\u{ef}n/\u{fc}nicode.txt")
|
||||
t:check(u and u.utf8 and z:readString(u) == "h\u{e9}llo", "unicode name")
|
||||
local m = z:find("readme.txt").modified
|
||||
t:check(m.year == 2020 and m.month == 5 and m.day == 17 and m.hour == 13 and m.min == 37 and m.sec == 42, "dos time")
|
||||
t:eq(z:find("readme.txt").mtime, 1589722662, "mtime (unix seconds)")
|
||||
local _, e = z:read("nope")
|
||||
t:check(e and e.code == Err.ARG, "read a missing name")
|
||||
t:eq(string.sub(byName.comment.zip.comment, 1, 14), "a comment with", "archive comment")
|
||||
t:check(byName.zip64_by_hand.zip.zip64 and byName.many.zip.zip64, "zip64 records detected")
|
||||
t:check(bit32.band(byName.descriptors.zip:list()[1].flags, 8) ~= 0, "data descriptor flag")
|
||||
t:check(not byName.basic.zip.zip64, "basic is not zip64")
|
||||
t:eq(byName.many.zip:readString("d/65999.txt"), "65999", "last of 66000 entries")
|
||||
t:eq(#byName.empty.zip:list(), 0, "empty archive")
|
||||
t:check(Zip.isZip(byName.basic.data) and Zip.isZip(byName.empty.data) and not Zip.isZip("GIF89a"), "isZip")
|
||||
-- a sub-range reader
|
||||
local s = byName.basic.data
|
||||
local big = buffer.create(#s + 10)
|
||||
buffer.writestring(big, 4, s)
|
||||
local zs = Zip.open(Bytes.reader(big, 4, #s))
|
||||
t:check(zs and zs:readString("readme.txt") ~= nil, "open a sub-range Reader")
|
||||
end
|
||||
|
||||
-- a bad CRC, encrypted and unsupported entries
|
||||
do
|
||||
local data = buffer.fromstring(byName.basic.data)
|
||||
local z = Zip.open(byName.basic.data)
|
||||
local st = z:find("stored.bin")
|
||||
local p = st.offset + 30 + buffer.readu16(data, st.offset + 26) + buffer.readu16(data, st.offset + 28) + 10
|
||||
buffer.writeu8(data, p, bit32.bxor(buffer.readu8(data, p), 0xFF))
|
||||
local z2 = Zip.open(data)
|
||||
local out, err = z2:read("stored.bin")
|
||||
t:check(out == nil and err.code == Err.CHECKSUM, "stored CRC mismatch: " .. tostring(err))
|
||||
t:check(z2:read("stored.bin", false) ~= nil, "verify = false")
|
||||
local e = table.clone(z:find("readme.txt"))
|
||||
e.flags = 1
|
||||
local _, ee = z:read(e)
|
||||
t:check(ee and ee.code == Err.UNSUPPORTED, "encrypted refused")
|
||||
e.flags, e.method = 0, 12
|
||||
local _, merr = z:read(e)
|
||||
t:check(merr and merr.code == Err.UNSUPPORTED and string.find(merr.message, "method 12", 1, true), "bzip2 refused: " .. tostring(merr))
|
||||
local _, oe = Zip.open(5 :: any)
|
||||
t:check(oe and oe.code == Err.ARG, "a non-buffer argument")
|
||||
end
|
||||
|
||||
-- the writer
|
||||
do
|
||||
local rand = T.rng(5)
|
||||
local w = Zip.writer()
|
||||
local files = {}
|
||||
local text = string.rep("the quick brown fox jumps over the lazy dog ", 2000)
|
||||
local noise = buffer.create(5000)
|
||||
for i = 0, 4999 do
|
||||
buffer.writeu8(noise, i, rand(2147483648) // 8388608)
|
||||
end
|
||||
local function put(name: string, data: any, opts: any?)
|
||||
t:check(w:add(name, data, opts), "add " .. name)
|
||||
table.insert(files, { name, if type(data) == "string" then data elseif data then buffer.tostring(data) else "" })
|
||||
end
|
||||
put("text.txt", text, { level = 9, mtime = 1589722662 })
|
||||
put("stored.txt", text, { method = "store" })
|
||||
put("noise.bin", noise) -- deflate is not smaller: stored
|
||||
put("empty.txt", "")
|
||||
put("dir/", nil)
|
||||
put("dir/\u{fc}nicode.txt", "h\u{e9}llo", { comment = "a file comment" })
|
||||
put("level0.txt", text, { level = 0 })
|
||||
local out, err = w:finish({ comment = "archive comment" })
|
||||
t:check(out, "finish: " .. tostring(err))
|
||||
local z = Zip.open(out :: buffer)
|
||||
t:check(z, "our archive opens")
|
||||
local list = z:list()
|
||||
t:eq(#list, #files, "entry count")
|
||||
for i, f in files do
|
||||
t:eq(list[i].name, f[1], "name " .. i)
|
||||
t:eq(z:readString(list[i]), f[2], "content " .. f[1])
|
||||
end
|
||||
t:eq(list[1].method, 8, "deflated")
|
||||
t:check(list[1].compressedSize < #text // 10, "compressed")
|
||||
t:eq(list[2].method, 0, "stored")
|
||||
t:eq(list[3].method, 0, "incompressible data is stored")
|
||||
t:check(list[5].isDir, "directory entry")
|
||||
t:check(list[6].utf8 and not list[1].utf8, "UTF-8 flag only for non-ASCII names")
|
||||
t:eq(list[6].comment, "a file comment", "entry comment")
|
||||
t:eq(list[1].mtime, 1589722662, "mtime round trip")
|
||||
local md = list[1].modified
|
||||
t:check(md.year == 2020 and md.month == 5 and md.day == 17 and md.hour == 13 and md.min == 37 and md.sec == 42, "dos time written")
|
||||
t:check(list[2].modified.year == 1980 and list[2].modified.month == 1 and list[2].modified.day == 1, "default time 1980-01-01")
|
||||
t:eq(z.comment, "archive comment", "archive comment written")
|
||||
t:check(not z.zip64, "small archive is not ZIP64")
|
||||
-- forced ZIP64
|
||||
local w64 = Zip.writer()
|
||||
w64:add("a.txt", text)
|
||||
w64:add("b.txt", "bee", { method = "store" })
|
||||
local z64 = Zip.open(w64:finish({ zip64 = true }) :: buffer)
|
||||
t:check(z64 and z64.zip64 and z64:readString("a.txt") == text and z64:readString("b.txt") == "bee", "forced ZIP64 round trip")
|
||||
-- over 65535 entries: the ZIP64 end record
|
||||
local wm = Zip.writer()
|
||||
for i = 0, 65999 do
|
||||
wm:add(string.format("d/%05d.txt", i), tostring(i), { method = "store" })
|
||||
end
|
||||
local zm = Zip.open(wm:finish() :: buffer)
|
||||
t:check(zm and zm.zip64 and #zm:list() == 66000 and zm:readString("d/65999.txt") == "65999", "66000 entries")
|
||||
-- dates
|
||||
for _, s in { 315532800, 946684799, 1700000000, 4354819198 } do
|
||||
local tm, dt = Zip.dosTime(s)
|
||||
t:eq(Zip.unixTime(tm, dt), s - s % 2, "dos time of " .. s)
|
||||
end
|
||||
t:check(select(2, Zip.dosTime(0)) == 0x21, "before 1980 clamps")
|
||||
-- bad arguments
|
||||
t:check(not w:add("", "x"), "empty name")
|
||||
t:check(not w:add("x", 5 :: any), "bad data")
|
||||
t:check(not w:add("x", "y", { method = "lzma" } :: any), "bad method")
|
||||
end
|
||||
|
||||
-- the Archive (archive/zip)
|
||||
do
|
||||
t:eq(ZipF.name, "zip", "name")
|
||||
t:eq(ZipF.category, "archive", "category")
|
||||
local a, err = ZipF.decode(Bytes.reader(buffer.fromstring(byName.basic.data)))
|
||||
t:check(a and a.kind == "archive" and a.format == "zip", "decode: " .. tostring(err))
|
||||
local list = a:list()
|
||||
t:eq(#list, byName.basic.count, "list")
|
||||
t:check(list[1].name == "readme.txt" and list[1].method == "deflate" and not list[1].dir and list[1].mtime == 1589722662, "entry fields")
|
||||
t:check(list[4].dir, "dir entry")
|
||||
local rd = a:read("readme.txt")
|
||||
t:check(rd and Crc32.of(rd :: buffer) == byName.basic.entries[1][3], "read")
|
||||
t:check(a:read("MAIN.bmp") ~= nil, "read by the lookup rules")
|
||||
-- edit: replace, add, remove, then write; unchanged entries are copied raw
|
||||
a:add("readme.txt", "replaced")
|
||||
a:add("new/one.txt", string.rep("x", 1000), { level = 9 })
|
||||
t:check(a:remove("Skin/stored.bin") and not a:remove("nope"), "remove")
|
||||
local out = a:write() :: buffer
|
||||
local b = ZipF.decode(Bytes.reader(out)) :: any
|
||||
t:check(b, "rewritten archive opens")
|
||||
t:eq(buffer.tostring(b:read("readme.txt")), "replaced", "replaced entry")
|
||||
t:eq(buffer.tostring(b:read("new/one.txt")), string.rep("x", 1000), "added entry")
|
||||
t:check(b:read("Skin/stored.bin") == nil, "removed entry")
|
||||
t:check(b:read("Skin/Main.BMP") and Crc32.of(b:read("Skin/Main.BMP")) == byName.basic.entries[2][3], "copied entry")
|
||||
local names = {}
|
||||
for _, e in b:list() do
|
||||
table.insert(names, e.name)
|
||||
end
|
||||
t:eq(table.concat(names, ","), "readme.txt,Skin/Main.BMP,Skin/,Skin/sub/deep.txt,empty.txt,__MACOSX/Skin/._Main.BMP,Sk\u{ef}n/\u{fc}nicode.txt,new/one.txt", "order kept")
|
||||
-- create, encode of a table, encode of another Archive
|
||||
local c = ZipF.create()
|
||||
c:add("hello.txt", "hi")
|
||||
local cz = ZipF.decode(Bytes.reader(ZipF.encode(c) :: buffer)) :: any
|
||||
t:eq(buffer.tostring(cz:read("hello.txt")), "hi", "create + encode")
|
||||
local tz = ZipF.decode(Bytes.reader(ZipF.encode({ ["b.txt"] = "bee", ["a.txt"] = buffer.fromstring("ay") }) :: buffer)) :: any
|
||||
t:check(tz:list()[1].name == "a.txt" and buffer.tostring(tz:read("b.txt")) == "bee", "encode a { name = data } table")
|
||||
local _, ee = ZipF.encode(5 :: any)
|
||||
t:check(ee and ee.code == Err.ARG, "encode a number")
|
||||
-- comments survive a rewrite
|
||||
local cm = ZipF.decode(Bytes.reader(buffer.fromstring(byName.comment.data))) :: any
|
||||
t:eq(string.sub(Zip.open(cm:write()).comment, 1, 14), "a comment with", "comment kept on write")
|
||||
-- the api
|
||||
local la = F.archive.load(byName.basic.data)
|
||||
t:check(la and la.kind == "archive" and #la:list() == byName.basic.count, "F.archive.load")
|
||||
t:eq(F.detect(byName.basic.data), "zip", "F.detect")
|
||||
local saved = F.save(la, nil, { format = "zip" })
|
||||
t:check(saved and #Zip.open(saved):list() == byName.basic.count, "F.save zip")
|
||||
local saved2 = F.save(la)
|
||||
t:check(saved2 ~= nil, "F.save without a format uses the source format")
|
||||
end
|
||||
|
||||
-- corrupt archives never throw
|
||||
local samples = {}
|
||||
for _, a in Fx.archives do
|
||||
if a.data then
|
||||
table.insert(samples, a.data)
|
||||
end
|
||||
end
|
||||
t:fuzz("open + read every entry", function(b: buffer)
|
||||
local z = Zip.open(b)
|
||||
if z then
|
||||
for _, e in z:list() do
|
||||
z:read(e)
|
||||
end
|
||||
end
|
||||
return z
|
||||
end, samples, { mutations = 40 })
|
||||
t:fuzz("archive decode + write", function(b: buffer)
|
||||
local a = ZipF.decode(Bytes.reader(b))
|
||||
if a then
|
||||
for _, e in a:list() do
|
||||
a:read(e.name)
|
||||
end
|
||||
a:write()
|
||||
end
|
||||
return a
|
||||
end, samples, { mutations = 10, garbage = 50 })
|
||||
|
||||
t:done()
|
||||
@@ -0,0 +1,203 @@
|
||||
-- audio/flac tests: every fixture from tools/fixtures/flac.py (flac 0-8, 4-32 bits, 1-6 channels, odd rates and block
|
||||
-- sizes, LPC order 32, wasted bits, every stereo mode, ffmpeg's encoder, Ogg FLAC, ID3v2 in front) decoded bit-exact
|
||||
-- against `flac -d`; sample-accurate seeking; f32 scaling and output reuse; decode() to an Audio from a sub-range
|
||||
-- Reader; tags and pictures; the length from the last frame; sniff; the api; damaged frames skipped; the fuzz pass.
|
||||
-- Ported from flac-luau tests/flac.luau. Fixtures: tools/fixtures/flac.py.
|
||||
local T = require("@tests/T")
|
||||
local Flac = require("@formats/audio/flac")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local F = require("@formats")
|
||||
local Cases = require("@tests/gen/flac_cases")
|
||||
|
||||
local t = T.suite("flac")
|
||||
|
||||
local function open(b: any, opts: any?): (any, any)
|
||||
return Flac.open(Bytes.reader(if type(b) == "string" then buffer.fromstring(b) else b), opts)
|
||||
end
|
||||
local byName = {}
|
||||
for _, c in Cases do
|
||||
byName[c.name] = c
|
||||
end
|
||||
|
||||
t:eq(Flac.name, "flac", "name")
|
||||
t:check(Flac.caps.decode and not Flac.caps.encode, "caps")
|
||||
|
||||
local seekChecks = 0
|
||||
for _, fx in Cases do
|
||||
local name = fx.name
|
||||
local dec, err = open(fx.data)
|
||||
t:check(dec, name .. ": open: " .. tostring(err))
|
||||
t:check(dec.sampleRate == fx.rate and dec.channels == fx.channels and dec.bitsPerSample == fx.bps, name .. ": format")
|
||||
t:eq(dec.frames, fx.frames, name .. ": frames")
|
||||
t:check(math.abs(dec.duration - fx.frames / fx.rate) < 1e-9, name .. ": duration")
|
||||
t:eq(dec.container, if fx.ogg then "ogg" else "flac", name .. ": container")
|
||||
local ch = dec.channels
|
||||
local all = table.create(fx.frames * ch, 0)
|
||||
local crc, n, k = 0, 0, 0
|
||||
local sizes = { 4096, 1, 777, 10000, 3 }
|
||||
while true do
|
||||
k += 1
|
||||
local out, got = dec:readInt(sizes[k % #sizes + 1])
|
||||
if got == 0 then
|
||||
break
|
||||
end
|
||||
crc = Crc32.of(out, 0, got * ch * 4, crc)
|
||||
for i = 0, got * ch - 1 do
|
||||
all[n * ch + i + 1] = buffer.readi32(out, i * 4)
|
||||
end
|
||||
n += got
|
||||
end
|
||||
t:eq(n, fx.frames, name .. ": decoded frames")
|
||||
t:eq(crc, fx.crc, name .. ": samples identical to flac -d")
|
||||
t:eq(select(2, dec:position()), fx.frames, name .. ": position at end")
|
||||
-- f32 scaling, output reuse
|
||||
dec:seekSample(0)
|
||||
local reuse = buffer.create(100 * ch * 4)
|
||||
local f, gotf = dec:read(100, reuse)
|
||||
t:check(f == reuse, name .. ": output buffer reused")
|
||||
local scale = 2 ^ (fx.bps - 1)
|
||||
local bad = 0
|
||||
for i = 0, math.min(gotf, 100) * ch - 1 do
|
||||
if math.abs(buffer.readf32(f, i * 4) - all[i + 1] / scale) >= 1e-7 then
|
||||
bad += 1
|
||||
end
|
||||
end
|
||||
t:eq(bad, 0, name .. ": f32 samples")
|
||||
-- seeking
|
||||
local rand = T.rng(99)
|
||||
local targets = { 0, 1, fx.frames - 1, fx.frames // 2, 4096, 4095, 4097, 1152, 1151 }
|
||||
for _ = 1, 12 do
|
||||
table.insert(targets, rand(fx.frames))
|
||||
end
|
||||
for _, s in targets do
|
||||
if s >= 0 and s < fx.frames then
|
||||
t:check(dec:seekSample(s), name .. ": seek " .. s)
|
||||
t:eq(select(2, dec:position()), s, name .. ": position after seek " .. s)
|
||||
local out, got = dec:readInt(50)
|
||||
t:eq(got, math.min(50, fx.frames - s), name .. ": read after seek")
|
||||
local diff = 0
|
||||
for i = 0, got * ch - 1 do
|
||||
if buffer.readi32(out, i * 4) ~= all[s * ch + i + 1] then
|
||||
diff += 1
|
||||
end
|
||||
end
|
||||
t:eq(diff, 0, name .. ": samples after seek " .. s)
|
||||
seekChecks += 1
|
||||
end
|
||||
end
|
||||
dec:seek(dec.duration / 3)
|
||||
local _, pos = dec:position()
|
||||
t:check(math.abs(pos - fx.frames / 3) <= 1, name .. ": seek seconds")
|
||||
dec:seek(dec.duration + 5)
|
||||
t:eq(select(2, dec:read(10)), 0, name .. ": read past the end")
|
||||
for key, v in fx.tags or {} do
|
||||
t:eq(dec.tags[key], v, name .. ": tag " .. key)
|
||||
end
|
||||
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring(fx.data))), 1, name .. ": sniff")
|
||||
end
|
||||
t:note("%d fixtures bit-exact against flac -d, %d seeks", #Cases, seekChecks)
|
||||
|
||||
-- decode() from a sub-range Reader
|
||||
for _, name in { "s16_l5", "ogg_s16", "id3", "s24_96k" } do
|
||||
local fx = byName[name]
|
||||
local big = buffer.create(#fx.data + 13)
|
||||
buffer.writestring(big, 6, fx.data)
|
||||
local a, err = Flac.decode(Bytes.reader(big, 6, #fx.data))
|
||||
t:check(a and a.kind == "audio" and a.frames == fx.frames and a.channels == fx.channels, name .. ": decode: " .. tostring(err))
|
||||
local d = open(fx.data)
|
||||
local ref = d:read(fx.frames)
|
||||
t:check(buffer.tostring(ref) == buffer.tostring(a.samples), name .. ": decode = read")
|
||||
t:eq(a.meta.source.bitDepth, fx.bps, name .. ": meta.source")
|
||||
end
|
||||
|
||||
-- tags and pictures
|
||||
do
|
||||
local dec = open(byName.s16_noseek.data)
|
||||
t:check(#dec.pictures == 1 and dec.pictures[1].mime == "image/png" and dec.pictures[1].width == 1, "picture")
|
||||
t:eq(#dec.seekTable, 0, "no seek table")
|
||||
t:check(string.find(dec.vendor, "reference libFLAC", 1, true), "vendor")
|
||||
t:eq(#dec.md5, 32, "md5")
|
||||
end
|
||||
|
||||
-- STREAMINFO without a total length: found from the last frame
|
||||
for _, name in { "s16_l5", "varblock", "bs17" } do
|
||||
local fx = byName[name]
|
||||
local b = buffer.fromstring(fx.data)
|
||||
buffer.writeu8(b, 8 + 13, bit32.band(buffer.readu8(b, 8 + 13), 0xF0))
|
||||
buffer.writeu32(b, 8 + 14, 0)
|
||||
local dec = open(b)
|
||||
t:check(dec and dec.frames == fx.frames, name .. ": length from the last frame")
|
||||
local crc, n = 0, 0
|
||||
while true do
|
||||
local out, got = dec:readInt(5000)
|
||||
if got == 0 then
|
||||
break
|
||||
end
|
||||
crc = Crc32.of(out, 0, got * dec.channels * 4, crc)
|
||||
n += got
|
||||
end
|
||||
t:check(n == fx.frames and crc == fx.crc, name .. ": decode without total length")
|
||||
end
|
||||
|
||||
-- sniff, errors, the api
|
||||
do
|
||||
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xxfLaC"))), 1, "sniff ID3 + fLaC")
|
||||
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("ID3\4\0\0\0\0\0\2xx\255\251"))), 0, "sniff ID3 + mp3")
|
||||
t:eq(Flac.sniff(Bytes.reader(buffer.fromstring("RIFF"))), 0, "sniff RIFF")
|
||||
local _, e1 = open("fLaC")
|
||||
t:check(e1 and Err.is(e1), "no metadata: " .. tostring(e1))
|
||||
local _, e2 = open(buffer.create(0))
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "empty")
|
||||
local fx = byName.ogg_s16
|
||||
t:eq(F.detect(fx.data), "flac", "F.detect Ogg FLAC")
|
||||
local a = F.audio.load(fx.data)
|
||||
t:check(a and a.frames == fx.frames, "F.audio.load")
|
||||
local d = F.audio.open(byName.s16_l3.data)
|
||||
t:check(d and d.frames == byName.s16_l3.frames, "F.audio.open")
|
||||
local _, se = F.save(a, nil, { format = "flac" })
|
||||
t:check(se and se.code == Err.UNSUPPORTED, "F.save flac is read-only here: " .. tostring(se))
|
||||
end
|
||||
|
||||
-- a damaged frame is dropped, the rest decodes
|
||||
do
|
||||
local src = buffer.fromstring(byName.s16_l5.data)
|
||||
local len = buffer.len(src)
|
||||
buffer.writeu8(src, len // 2, bit32.bxor(buffer.readu8(src, len // 2), 0x55))
|
||||
local d = open(src)
|
||||
local total = 0
|
||||
while true do
|
||||
local _, got = d:read(4096)
|
||||
if got == 0 then
|
||||
break
|
||||
end
|
||||
total += got
|
||||
end
|
||||
t:check(total < d.frames and total >= d.frames - 2 * 4096, "one damaged frame dropped: " .. total)
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
local samples = {}
|
||||
for _, name in { "s16_l5", "ogg_s16", "id3", "varblock", "s32_rice2", "u8_mono", "bits4" } do
|
||||
table.insert(samples, byName[name].data)
|
||||
end
|
||||
t:fuzz("open + read + seek", function(b: buffer)
|
||||
local d = Flac.open(Bytes.reader(b))
|
||||
if d then
|
||||
local guard = 0
|
||||
while select(2, d:read(4096)) > 0 and guard < 200 do
|
||||
guard += 1
|
||||
end
|
||||
d:seek(0.1)
|
||||
d:read(100)
|
||||
d:seekSample(d.frames // 2)
|
||||
d:read(100)
|
||||
end
|
||||
return d
|
||||
end, samples, { mutations = 12, keepHeader = 42 })
|
||||
t:fuzz("decode", function(b: buffer)
|
||||
return Flac.decode(Bytes.reader(b))
|
||||
end, samples, { mutations = 6, garbage = 60 })
|
||||
|
||||
t:done()
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 273 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 7.8 KiB |
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 64 KiB |
@@ -0,0 +1,27 @@
|
||||
g/pal1.bmp pal1.png
|
||||
g/pal1bg.bmp pal1bg.png
|
||||
g/pal1wb.bmp pal1.png
|
||||
g/pal4.bmp pal4.png
|
||||
g/pal4gs.bmp pal4gs.png
|
||||
g/pal4rle.bmp pal4.png
|
||||
g/pal8-0.bmp pal8.png
|
||||
g/pal8.bmp pal8.png
|
||||
g/pal8gs.bmp pal8gs.png
|
||||
g/pal8nonsquare.bmp pal8nonsquare-v.png
|
||||
g/pal8os2.bmp pal8.png
|
||||
g/pal8rle.bmp pal8.png
|
||||
g/pal8topdown.bmp pal8.png
|
||||
g/pal8v4.bmp pal8.png
|
||||
g/pal8v5.bmp pal8.png
|
||||
g/pal8w124.bmp pal8w124.png
|
||||
g/pal8w125.bmp pal8w125.png
|
||||
g/pal8w126.bmp pal8w126.png
|
||||
g/rgb16-565.bmp rgb16-565.png
|
||||
g/rgb16-565pal.bmp rgb16-565.png
|
||||
g/rgb16.bmp rgb16.png
|
||||
g/rgb16bfdef.bmp rgb16.png
|
||||
g/rgb24.bmp rgb24.png
|
||||
g/rgb24pal.bmp rgb24.png
|
||||
g/rgb32.bmp rgb24.png
|
||||
g/rgb32bf.bmp rgb24.png
|
||||
g/rgb32bfdef.bmp rgb24.png
|
||||
|
After Width: | Height: | Size: 586 B |
|
After Width: | Height: | Size: 604 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 11 KiB |