Skip to content

Prevent HTML minification from corrupting embedded WASM data - #27509

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:fix-html-minifier-custom-fragments
Open

Prevent HTML minification from corrupting embedded WASM data#27509
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:fix-html-minifier-custom-fragments

Conversation

@sbc100

@sbc100 sbc100 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Pass --ignore-custom-fragments '[]' to html-minifier-terser.

By default, html-minifier-terser includes custom fragment regexes
/<%[\s\S]*?%>/ and /<\?[\s\S]*?\?>/ intended for ignoring server-side
preprocessor tags (like PHP <?php ... ?> or ASP <% ... %>). When
matching these fragments, html-minifier-terser matches surrounding
whitespace \s* and collapses it.

When WASM binary data is embedded in JavaScript inside an HTML file
(such as in -sSINGLE_FILE=1 builds), arbitrary byte sequences in the
WASM binary can happen to match <?...?> or <%...%>. In these cases,
html-minifier-terser mistakes the binary data for preprocessor tags
and collapses surrounding spaces (0x20 bytes), corrupting the embedded
WASM binary payload.

Passing --ignore-custom-fragments '[]' disables this behavior. It is
safe for Emscripten because generated HTML files are standard
client-side documents, not server-side PHP/ASP template files containing
preprocessor tags.

Fixes: #27156

Pass `--ignore-custom-fragments '[]'` to `html-minifier-terser`.

By default, `html-minifier-terser` includes custom fragment regexes
`/<%[\s\S]*?%>/` and `/<\?[\s\S]*?\?>/` intended for ignoring server-side
preprocessor tags (like PHP `<?php ... ?>` or ASP `<% ... %>`). When
matching these fragments, `html-minifier-terser` matches surrounding
whitespace `\s*` and collapses it.

When WASM binary data is embedded in JavaScript inside an HTML file
(such as in `-sSINGLE_FILE=1` builds), arbitrary byte sequences in the
WASM binary can happen to match `<?...?>` or `<%...%>`. In these cases,
`html-minifier-terser` mistakes the binary data for preprocessor tags
and collapses surrounding spaces (`0x20` bytes), corrupting the embedded
WASM binary payload.

Passing `--ignore-custom-fragments '[]'` disables this behavior. It is
safe for Emscripten because generated HTML files are standard
client-side documents, not server-side PHP/ASP template files containing
preprocessor tags.

Fixes: emscripten-core#27156
@sbc100 sbc100 changed the title [link] Prevent HTML minification from corrupting embedded WASM data Prevent HTML minification from corrupting embedded WASM data Aug 9, 2026
@sbc100
sbc100 force-pushed the fix-html-minifier-custom-fragments branch from c5f933d to ef74478 Compare August 9, 2026 19:15
@sbc100 sbc100 changed the title Prevent HTML minification from corrupting embedded WASM data [link] Prevent HTML minification from corrupting embedded WASM data Aug 9, 2026
@sbc100 sbc100 changed the title [link] Prevent HTML minification from corrupting embedded WASM data Prevent HTML minification from corrupting embedded WASM data Aug 9, 2026
@sbc100
sbc100 requested review from dschuff and kripken August 9, 2026 19:16
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.

WebAssembly.instantiate(): illegal flag value 90 @+642213 when -sSINGLE_FILE=1 in release build

1 participant