What a file is, read from its first bytes rather than from its name or the
browser's Content-Type — both of which are the uploader's claims.
Two uses:
- at upload,
Storagelets a sniffed raster image type overrule the claimed one, and stops a file that claims to be a raster image but is not from being handed to the image pipeline; - before ImageMagick touches a file,
ImageProcessorpins the decoder to the sniffed raster format (png:/tmp/x), so a file can never be read by a coder nobody meant to run.
Only the formats in raster_formats/0 are ever given to ImageMagick. SVG,
PDF, PostScript/EPS, MVG, MSL and the rest reach their decoders through
delegates (librsvg, Ghostscript…) with a long history of command injection
and memory-safety bugs; they are recognised here so they can be refused,
never pinned.
Summary
Functions
The ImageMagick coder name that pins decoding to format
("png" → png:/path), or nil for anything that must not reach
ImageMagick.
The MIME type for a sniffed format.
Whether format is one ImageMagick may be given.
The raster formats ImageMagick may decode, each with a pinned coder.
Reads the first bytes of the file at path and names its format.
:unknown for anything unrecognised or unreadable.
sniff/1 over bytes already in memory (the first ~512 are enough).
Types
Functions
The ImageMagick coder name that pins decoding to format
("png" → png:/path), or nil for anything that must not reach
ImageMagick.
The MIME type for a sniffed format.
Whether format is one ImageMagick may be given.
@spec raster_formats() :: [format()]
The raster formats ImageMagick may decode, each with a pinned coder.
Reads the first bytes of the file at path and names its format.
:unknown for anything unrecognised or unreadable.
sniff/1 over bytes already in memory (the first ~512 are enough).