Repository navigation
fix(engine): gracefully handle binary responses and wrap decode failures in TransportLayerException - #999
Open
Reginald Alfret V (reginaldalfret) wants to merge 1 commit into
Conversation
…res in TransportLayerException Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
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.
Description
When fuzzing or testing endpoints that return binary data (e.g. downloading
.ziparchives,application/octet-stream, image files, or other binary formats), the RESTler engine previously crashed with an unhandledUnicodeDecodeError: 'utf-8' codec can't decode byte ....Root Cause
HttpSock._recvResponse,decode_buf(buf)unconditionally calledbuf.decode(UTF8).recvreturns the HTTP headers followed immediately by the binary response payload. Because the payload contains non-UTF-8 bytes,buf.decode(UTF8)failed.ignore_decoding_failureswas not enabled (Falseby default),decode_bufre-raisedUnicodeDecodeError. BecausesendRecvonly caughtTransportLayerException, the exception propagated unhandled up through the engine execution stack and aborted the fuzzing run.Solution
decode_buf:self.ignore_decoding_failuresis set, continue logging and decoding with"ignore".DELIM in data), decode the body using"replace"errors so the payload is safely preserved without crashing.b"\r\n\r\n" in buf), cleanly partition headers and body at the delimiter, decode the headers, and decode the body with"replace".TransportLayerExceptioninstead of an unhandledUnicodeDecodeError, allowingsendRecvto handle and log the failure cleanly.utils.logging.trace_db as trace_db.unit_tests/test_messaging.pyvalidating single-buffer and multi-buffer binary response handling, header decode failure handling, and setting override.Closes #976.