Skip to content

Fix corruption of binary responses caused by UTF-8 decoding in proxy response#960

Open
SelvaRM04 wants to merge 1 commit into
trinodb:mainfrom
SelvaRM04:binary-response-corruption
Open

Fix corruption of binary responses caused by UTF-8 decoding in proxy response#960
SelvaRM04 wants to merge 1 commit into
trinodb:mainfrom
SelvaRM04:binary-response-corruption

Conversation

@SelvaRM04
Copy link
Copy Markdown

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:

Gateway 3

Gateway 5

After this change:
/ui/assets/logo.png loads correctly through gateway

Gateway 4

Gateway 6

Additional 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.

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 13, 2026

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

@SelvaRM04
Copy link
Copy Markdown
Author

Submitted the signed copy of CLA. Please review and add my name to contributors.

@oneonestar
Copy link
Copy Markdown
Member

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Apr 1, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 1, 2026

The cla-bot has been summoned, and re-checked this pull request!

@Chaho12
Copy link
Copy Markdown
Member

Chaho12 commented Apr 15, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@Chaho12 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 39 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca309287-c47d-492d-9a98-a91cdabd34b0

📥 Commits

Reviewing files that changed from the base of the PR and between 3c20855 and 91670c2.

📒 Files selected for processing (1)
  • gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseHandler.java

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@Chaho12
Copy link
Copy Markdown
Member

Chaho12 commented May 6, 2026

Let me know if you are ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants