Handle tiny files gracefully
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success

Lua detection functions used to cause fatal errors on failure to read.

We could also reconsider treating detection errors as fatal.
This commit is contained in:
Přemysl Eric Janouch 2024-12-08 22:36:02 +01:00
parent 189bf94034
commit 019c4302ad
Signed by: p
GPG Key ID: A0420B94F92B9493
6 changed files with 13 additions and 4 deletions

View File

@ -18,7 +18,7 @@
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
local detect = function (c)
return c:read (4) == "\x7FELF"
return #c >= 4 and c:read (4) == "\x7FELF"
end
local ph_type_table = {

View File

@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (2) == "\x1f\x8b"
return #c >= 2 and c:read (2) == "\x1f\x8b"
end
local function latin1_to_utf8 (s)

View File

@ -16,11 +16,17 @@
--
local detect = function (c)
if #c < 4 then
return false
end
local magic = c:u32 ()
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
end
local detect_ng = function (c)
if #c < 8 then
return false
end
local magic = c (9):u32 ()
return c:u32 () == 0x0a0d0d0a
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)

View File

@ -335,7 +335,7 @@ end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
local detect = function (c)
return c:read (5) == "%PDF-"
return #c >= 5 and c:read (5) == "%PDF-"
end
local decode_xref_subsection = function (lex, start, count, result)

View File

@ -16,6 +16,9 @@
--
local detect = function (c)
if #c < 68 then
return false
end
c.position = 65
return c:read (4) == "\x7F\x10\xDA\xBE"
end

View File

@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (4) == "Xcur"
return #c >= 4 and c:read (4) == "Xcur"
end
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml