[luatex] Prevent stop when tiff file loads

Nicolas Holzschuch Nicolas.Holzschuch at inria.fr
Fri Jan 22 08:08:14 CET 2016


> On 22 Jan 2016, at 07:45, Philipp Gesang <phg at phi-gamma.net> wrote:
> 
> ···<date: 2016-01-21, Thursday>···<from: luigi scarso>···
> 
>> On Thu, Jan 21, 2016 at 10:10 PM, Patrick Gundlach <patrick at gundla.ch>
>> wrote:
>> 
>>>>> Is there a way to prevent LuaTeX from stopping the whole process? Is
>>> there a function like
>>> 
>> Why not mimic the Unix file command in Lua ?
> 
> This is less trivial than it’d appear: file(1)’s recognition
> magic has been improved and battle-tested over the years. It’ll
> be hard to arrive at that level with a custom implementation,
> especially from a security standpoint: Scanning a well prepared
> user-supplied file can DOS your machine. Why not invoke file (or
> perhaps identify(1)) directly?

In practice, identifying all image files formats (tiff, png, pdf...) *should* work with the first 4 bytes of the file (they were designed this way). 

Sure, a well-prepared user-supplied file could pretend to be a PDF and kill your machine, but to answer the original question it would be enough to:
- scan the first 4 bytes of the file
- compare with a table ("%!PD" -> it must be a PDF, for example, "II42" -> it must be a Tiff, and so on)
- only load the file if it's one of the types that LuaTeX can handle. Anything that is not recognized defaults to "can not handle, don't load (without crashing)".

It's not the full behaviour of file(1), but it's a start. It's how file(1) was started, actually. 

Nicolas



> 
> Philipp
> 
> (A Lua implementation of file would be interesting though =))
> 




More information about the luatex mailing list