Repository navigation
fix(retinaface): reject malformed RLE counts before native decode - #2908
Open
huangkongsheng wants to merge 1 commit into
Open
huangkongsheng wants to merge 1 commit into
huangkongsheng wants to merge 1 commit into
Conversation
The vendored pycocotools accepted compressed RLE strings whose decoded
run lengths did not sum to the declared h*w. rleDecode() then trusted
the counts and wrote past the end of the mask allocation - a native
heap overflow reachable from untrusted COCO annotations
(_mask.decode([{size:[1,1], counts:b'02'}]) writes 2 bytes into a
1-byte mask, ASan-confirmed in issue deepinsight#2889).
rleFrString() now verifies the run-length total and produces an empty
RLE on mismatch; _frString() turns that into a ValueError, and
decode() additionally rejects RLEs with inconsistent sizes. Valid
encodings are unaffected (their total is h*w by definition).
Issue deepinsight#2889 has the full analysis and an ASan PoC.
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.
Fixes #2889
The vendored pycocotools accepted compressed RLE strings whose decoded run lengths did not sum to the declared h*w.
rleDecode()then trusted the counts and wrote past the end of the mask allocation - a native heap overflow reachable from untrusted COCO annotations. The ASan PoC in the issue (_mask.decode([{size:[1,1], counts:b'02'}])- 2 bytes written into a 1-byte mask) confirms it.Changes:
rleFrString()verifies the decoded run-length total equalsh*wand produces an empty RLE otherwise (also catches delta values that wrap into huge uint counts, and failed mallocs for non-empty strings)_frString()turns that empty RLE into aValueErrorso callers get a Python exception instead of silent corruptiondecode()additionally rejects a list of RLEs with inconsistent sizes (the buffer is sized from the first one)Valid encodings are unaffected - their run lengths total h*w by definition. Note I could not compile locally (no C toolchain on this machine), so the Cython build and the issue's PoC should be re-run by CI or a maintainer environment; the fix is deliberately small and localised to the two decode entry points.