Handle tiny files gracefully
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:
parent
189bf94034
commit
019c4302ad
@ -18,7 +18,7 @@
|
|||||||
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
|
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (4) == "\x7FELF"
|
return #c >= 4 and c:read (4) == "\x7FELF"
|
||||||
end
|
end
|
||||||
|
|
||||||
local ph_type_table = {
|
local ph_type_table = {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (2) == "\x1f\x8b"
|
return #c >= 2 and c:read (2) == "\x1f\x8b"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function latin1_to_utf8 (s)
|
local function latin1_to_utf8 (s)
|
||||||
|
@ -16,11 +16,17 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
|
if #c < 4 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local magic = c:u32 ()
|
local magic = c:u32 ()
|
||||||
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
|
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
|
||||||
end
|
end
|
||||||
|
|
||||||
local detect_ng = function (c)
|
local detect_ng = function (c)
|
||||||
|
if #c < 8 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local magic = c (9):u32 ()
|
local magic = c (9):u32 ()
|
||||||
return c:u32 () == 0x0a0d0d0a
|
return c:u32 () == 0x0a0d0d0a
|
||||||
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)
|
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)
|
||||||
|
@ -335,7 +335,7 @@ end
|
|||||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (5) == "%PDF-"
|
return #c >= 5 and c:read (5) == "%PDF-"
|
||||||
end
|
end
|
||||||
|
|
||||||
local decode_xref_subsection = function (lex, start, count, result)
|
local decode_xref_subsection = function (lex, start, count, result)
|
||||||
|
@ -16,6 +16,9 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
|
if #c < 68 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
c.position = 65
|
c.position = 65
|
||||||
return c:read (4) == "\x7F\x10\xDA\xBE"
|
return c:read (4) == "\x7F\x10\xDA\xBE"
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (4) == "Xcur"
|
return #c >= 4 and c:read (4) == "Xcur"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml
|
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml
|
||||||
|
Loading…
Reference in New Issue
Block a user