Repository navigation
Conversation
…oid pipe deadlock A command that writes non-UTF-8 bytes to stdout makes the reader thread raise UnicodeDecodeError (text=True defaults to strict decoding). The reader stops draining the pipe, the child blocks in write() once the 64KB buffer fills, and _reader's final proc.wait() hangs forever, freezing background shells and security scanners. Decode with errors="replace" so invalid bytes become U+FFFD and the reader keeps consuming the pipe until EOF. Fixes openhackai#13
|
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 #13.
Problem
subprocess.Popenis started withtext=Truebut withouterrors=, so decoding defaults to strict. When a command emits non-UTF-8 bytes, the reader thread raisesUnicodeDecodeError, itsexcept Exception: passswallows it, and the reader stops draining stdout. Once the child fills the 64KB OS pipe buffer, it blocks inwrite(), and_reader's finalproc.wait()hangs forever — freezing background shells and security scanners (strings, fuzzers, compiled-binary tests) indefinitely.Fix
Decode with
errors="replace"so invalid bytes become U+FFFD instead of raising, and the reader keeps consuming the pipe until EOF:stderr=subprocess.STDOUT, text=True, + errors="replace", bufsize=1,Verification
Added
test_non_utf8_output_does_not_deadlockintests/test_shells.py, which spawnspython3 -c '... sys.stdout.buffer.write(b"\xff" * 200000)'and asserts the shell exits (no deadlock),returncode == 0, and the invalid bytes are decoded as replacement characters rather than dropped.Reproduced the hang before the fix (shell stays
runningforever, child never reaped) and confirmed it exits cleanly after.