ws-cleanup-types: archive, audio, data, font, image, layered, music, playlist, subtitle, vector, video: annotations, casts, one value per re-assignment where the solver loses the type

This commit is contained in:
4DBug committed 2026-10-31 11:00:25 -05:00
1 parent dc98aec2ec
commit f459b2dcdf
44 files changed
+172 -119

No files matched your search

+4 -3
View File
@@ -177,7 +177,8 @@ local function folder(r: Bytes.Reader): Folder
check(r)
local nin, nout = 1, 1
if bit32.band(flags, 0x10) ~= 0 then
nin, nout = number(r), number(r)
nin = number(r)
nout = number(r)
if nin > 64 or nout > 64 then
bad(r, "bad coder stream count")
end
@@ -416,11 +417,11 @@ local function filesInfo(r: Bytes.Reader): { File }
if n > 1000000 then
bad(r, "too many files", Err.LIMIT)
end
local files: { File } = table.create(n)
local files: { File } = table.create(n) :: { File }
for i = 1, n do
files[i] = { name = "", emptyStream = false, emptyFile = false, anti = false }
end
local empties = {}
local empties: { number } = {}
while true do
local t = byte(r)
if t == K.End then
+10 -6
View File
@@ -144,7 +144,9 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
if not b then
return nil, e
end
src, so, sl = b, 0, buffer.len(b)
src = b
so = 0
sl = buffer.len(b)
else
local k = table.find(f.packed, inIdx)
if not k then
@@ -162,7 +164,7 @@ local function decodeFolder(ctx: Ctx, s: Header.Streams, f: Header.Folder): (buf
src = ctx.buf
end
local id = c.id
local opts = { maxBytes = ctx.maxBytes }
local opts: { maxBytes: number?, verify: boolean? } = { maxBytes = ctx.maxBytes }
if id == "\0" then
if sl < size then
return nil, Err.new(Err.TRUNCATED, "short stored stream")
@@ -226,7 +228,7 @@ local function folderMethod(f: Header.Folder): string
end
function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local maxBytes = if type(o.maxBytes) == "number" then o.maxBytes else 2 ^ 30
local checkCrc = o.checkCrc ~= false
local b, base, limit = r.buf, r.base, r.limit
@@ -280,17 +282,19 @@ function SevenZip.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?
if f.crc and Crc32.raw(hb, 0, buffer.len(hb)) ~= f.crc then
return nil, Err.new(Err.CHECKSUM, "encoded header CRC-32 mismatch")
end
hbuf, hoff, hlen = hb, 0, buffer.len(hb)
hbuf = hb
hoff = 0
hlen = buffer.len(hb)
end
if not parsed then
return nil, Err.new(Err.CORRUPT, "nested encoded headers")
end
local s = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
local s: Header.Streams = parsed.streams or { packPos = 0, packSizes = {}, folders = {}, subSizes = {}, subCrcs = {} }
a.meta.folders = #s.folders
a.meta.solid = false
-- folder caches and the substream -> folder map
local cache: { [number]: buffer } = {}
local subFolder, subOffset = {}, {}
local subFolder: { number }, subOffset: { number } = {}, {}
do
local si = 1
for fi, f in s.folders do
+4 -4
View File
@@ -49,7 +49,7 @@ local function header(b: buffer, o: number, e: number): { [string]: any }
if bit32.band(flg, 4) ~= 0 and q + 2 <= e then
q += 2 + buffer.readu16(b, q)
end
for _, f in { { 8, "name" }, { 16, "comment" } } do
for _, f in { { 8, "name" }, { 16, "comment" } } :: { { any } } do
if bit32.band(flg, f[1]) ~= 0 then
local s = q
while q < e and buffer.readu8(b, q) ~= 0 do
@@ -85,7 +85,7 @@ function Gzip.decode(r: Bytes.Reader, opts: DecodeOptions?): (any, Err.Err?)
size = buffer.len(out),
compressedSize = r.limit - r.base,
method = "deflate",
mtime = if h.mtime and h.mtime > 0 then h.mtime else nil,
mtime = if h.mtime and h.mtime > 0 then h.mtime :: number else nil,
dir = false,
data = out,
})
@@ -94,7 +94,7 @@ end
-- ------------------------------------------------------------------------------------------------ encode
function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
local o = opts or {}
local o: EncodeOptions = opts or {}
local level = if o.level == nil then 6 else o.level
if type(level) ~= "number" or level < 0 or level > 9 or level % 1 ~= 0 then
return nil, Err.new(Err.ARG, "level must be 0..9")
@@ -111,7 +111,7 @@ function Gzip.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
if not items then
return nil, Err.new(Err.ARG, "expected an Archive, a buffer or a string")
end
local files = {}
local files: typeof(items) = {}
for _, it in items do
if not it.entry.dir then
table.insert(files, it)
+1 -1
View File
@@ -70,7 +70,7 @@ end
-- ------------------------------------------------------------------------------------------------ decode
function Xz.decode(r: Bytes.Reader, opts: DecodeOptions?): (Types.Archive?, Err.Err?)
local o = opts or {}
local o: DecodeOptions = opts or {}
local n = r.limit - r.base
local out, res
local method