Skip to content

Ingest trusts the OS extension table over file bytes when detecting MIME type #561

Closed

Description

@rodboev

Docbank records a real JPEG as application/jpg on Windows when another program has rewritten the registry row for .jpg. Every feature that keys on the stored MIME type then treats the file as something other than an image.

Ingest resolves the type from the file extension first. It sniffs the bytes only when the extension is unknown, so a bad extension table wins over a valid JPEG header.

The photo asset work in #465 is the first feature to gate behavior on that type. On the affected machine a .jpg from a camera is refused as not eligible. A copy of the same bytes renamed .dng is enrolled.

Environment

Version v0.14.0-223-g92700038 on Windows 11. JPEGView writes Content Type = application/jpg under HKCR\.jpg when it claims the extension. Go's mime package loads that table at startup and lets it override the built-in list. Chrome and other browsers read the file header and are unaffected.

Reproduction

On a machine with the polluted row:

reg query HKCR\.jpg /v "Content Type"
docbank add C:\shoot --dest /photos
docbank ls /photos/shoot --json

The listing shows "mime_type":"application/jpg" for the JPEG. Setting the registry value back to image/jpeg and re-adding the file restores image/jpeg.

Proposed fixes

  1. Make the mimetype library the primary detector. It is already an indirect dependency, reads magic bytes for around 170 formats including DNG, CR2, NEF, and HEIC, and consults the extension only when the bytes are ambiguous. This fixes the registry case and gives the RAW slices under Roadmap: photos in Docbank #465 a detector that works on every platform.
  2. Keep the extension as a tiebreaker and as the only source for formats the sniffer cannot recognize, such as .xmp sidecars.
  3. Reject extension results that are not registered media types, such as application/jpg, and fall through to sniffing. This is a one-line guard that also catches other polluted rows.
  4. Decide whether existing rows are rewritten. Vaults already carrying wrong types keep them until the file is added again, so the fix needs a migration or a maintenance command to re-detect stored files.

A smaller alternative is to sniff with the standard library first and fall back to the extension. That fixes JPEG, PNG, GIF, and WebP but leaves camera RAW dependent on the extension table, so it lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions