fix(uploads): register HEIC/HEIF with the file validator + fix admin format hint (codex review of #832)

Two findings from the Codex review:

- validateFileType requires an ALLOWED_MEDIA_TYPES entry, which had neither
  image/heic nor image/heif — so HEIC was rejected before sharp ever saw it,
  despite the EXTENSION_TO_MIME additions. Added both with a single 'ftyp'
  (offset 4) magic number (the check is .every, so alternatives can't be
  separate entries).

- Changing the shared upload.fileRequirements string to interpolate {{formats}}
  left the admin PhotoUpload caller passing only { limit }, rendering the
  placeholder literally (it was also already dropping {{sizeLimit}} from #823).
  The admin caller now passes formats + sizeLimit + limit, from the admin
  settings it already loads.
This commit is contained in:
Paul Nothaft
2026-07-17 22:06:40 +02:00
parent 2b5b23b96f
commit c9b64d9c1a
2 changed files with 27 additions and 2 deletions
+16
View File
@@ -79,6 +79,22 @@ const ALLOWED_IMAGE_TYPES = {
extensions: ['.svg'],
// SVG files are XML-based text files, so we skip magic number validation
magicNumbers: null
},
// HEIC/HEIF (iPhone). ISO-BMFF container: bytes 4-7 are the "ftyp" box marker,
// present in every HEIF/HEIC file (single entry — the magic check is `.every`,
// so alternatives can't be listed as separate entries). Sharp's libvips
// decodes these; extension + MIME are already gated by validateFileType.
'image/heic': {
extensions: ['.heic'],
magicNumbers: [
{ offset: 4, bytes: [0x66, 0x74, 0x79, 0x70] } // "ftyp"
]
},
'image/heif': {
extensions: ['.heif'],
magicNumbers: [
{ offset: 4, bytes: [0x66, 0x74, 0x79, 0x70] } // "ftyp"
]
}
};