fix: add C >= 128 guards + fallback to all UTF-8 continuation validators in cow_ws (crash on malformed text frames)#160
Closed
dl-alexandre wants to merge 1 commit into
Conversation
…-s8) in cow_ws Prevents crash (badarg in element/2) on malformed or malicious WebSocket text frames containing out-of-range continuation bytes. This is the root cause of the UTF8 validation crash reported in ninenines#158. All states now consistently guard like validate_s0 does, and validate_ascii already does <128 fast path. Refs ninenines#158
Member
|
Thanks but #159 already has the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WebSocket text/close frames must be valid UTF-8. The state machine in cow_ws:validate_text/2 (and validate_sN helpers) assumed continuation states (s2-s8) would only ever see bytes >= 128.
A low byte (< 128) while in one of those states (e.g. truncated/malformed frame from network or adversarial input) caused element(C-127, utf8_class()) to receive an out-of-range index and crash (badarg; after partial guard also function_clause).
This is the root cause of the crash reported in #158.
Fix (smallest defensible change)
Valid UTF-8 paths (ASCII fast path, 2/3/4-byte sequences, fragmented text frames) are unaffected.
Testing
Local verification (no full erlang.mk TEST_DEPS fetch required):
This makes the UTF-8 validator robust against the reported class of input.
Fixes #158
(Contrib loop: claimed via work claim, investigated, smallest targeted change + manual property-like smoke on the exact crash scenario, self-verified compile+exec, now gating.)