Skip to content

Fix: skip Windows registry MIME entries with an invalid Content Type#17106

Open
SAY-5 wants to merge 1 commit into
crystal-lang:masterfrom
SAY-5:fix-win32-mime-invalid-content-type
Open

Fix: skip Windows registry MIME entries with an invalid Content Type#17106
SAY-5 wants to merge 1 commit into
crystal-lang:masterfrom
SAY-5:fix-win32-mime-invalid-content-type

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 2, 2026

Copy link
Copy Markdown

On Windows, Crystal::System::MIME.load reads MIME types from the registry and calls MIME.register for each .<ext>\Content Type entry. If any entry holds an empty or malformed value, MIME.register raises ArgumentError ("Invalid media type: ...") which is unrescued, so a single bad registry entry aborts MIME initialization and crashes the first MIME.from_extension call.

The Unix loader already guards each source with a bare rescue (src/crystal/system/unix/mime.cr). This mirrors that: the per-entry register is wrapped so an invalid entry is skipped instead of taking down the whole load.

Fixes #17103.

The failing path is Windows-registry-specific, so I couldn't add a portable spec that exercises load directly. I confirmed the behavior of the guarded loop with the same call load makes (registering a batch where one entry has an empty Content Type): before the guard the ArgumentError aborts the loop, after it the bad entry is skipped and the remaining extensions register.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@HertzDevil

Copy link
Copy Markdown
Contributor

While this is probably the right thing to do, did you encounter a corrupted registry naturally?

@Viktor-KN

Copy link
Copy Markdown

While this is probably the right thing to do, did you encounter a corrupted registry naturally?

I've reported this bug. Yes, registry corruption were encountered naturally on one of Windows 10 installations.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIME module crashes on Windows when registry contains invalid Content-Type

3 participants