Fix corruption of binary responses caused by UTF-8 decoding in proxy response#960
Fix corruption of binary responses caused by UTF-8 decoding in proxy response#960SelvaRM04 wants to merge 1 commit into
Conversation
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
|
Submitted the signed copy of CLA. Please review and add my name to contributors. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 58 minutes and 39 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Chaho12
left a comment
There was a problem hiding this comment.
I agree with the fix, where raw is the correct, but can you add a test in TestProxyRequestHandler to verify that a binary response body passes through without corruption?
|
Let me know if you are ready for review |
Description
The gateway currently reads backend responses using UTF-8 string decoding:
new String(response.getInputStream().readNBytes((int) responseSize.toBytes()), StandardCharsets.UTF_8)This will work for all text responses. But for binary assets like image/png, decoding binary content as UTF-8 modifies the byte stream, because invalid UTF-8 sequences are replaced or re-encoded. As a result, gateway returns corrupted/broken image to client.
One observable example is
'/ui/assets/logo.png'. This returns a broken image.Solution
Avoiding the conversion of response body to a UTF-8 string fixes this issue. Forward the raw bytes return by the backend ensures images are transmitted without modification.
response.getInputStream().readNBytes((int) responseSize.toBytes())Result
Before this change:
After this change:
/ui/assets/logo.pngloads correctly through gatewayAdditional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required, with the following suggested text:
* Fix some things.