fix(native): Replace unsafe atol() with folly::to<> in PrestoExchangeSource#27223
Merged
amitkdutta merged 1 commit intoprestodb:masterfrom Feb 27, 2026
Merged
fix(native): Replace unsafe atol() with folly::to<> in PrestoExchangeSource#27223amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta merged 1 commit intoprestodb:masterfrom
Conversation
…Source Summary: Replace `atol()` calls with `folly::to<>` when parsing HTTP response headers in `PrestoExchangeSource`. `atol()` silently returns 0 on empty/malformed input and has undefined behavior on overflow. `folly::to<>` throws on invalid input, making failures explicit rather than silently degrading. Two call sites fixed: - Content-Length header parsing (line ~301): guarded with an empty check since a missing Content-Length header is valid and should default to 0. - Next page token header parsing (line ~334): no empty guard needed since the caller already checks for non-empty. Differential Revision: D94573576
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces unsafe uses of C’s atol() in PrestoExchangeSource HTTP header parsing with folly::to<>, adding an explicit empty-header guard for Content-Length while relying on existing non-empty checks for the next-page token header. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Now that
folly::towill throw on malformedContent-Lengthor next-token headers, consider wrapping these conversions in a small helper that catchesfolly::ConversionErrorand rethrows with additional context (e.g., URL, header name, value) to make diagnosing bad upstream responses easier. - For
contentLength, you special-case the empty string to 0; if there is any possibility of whitespace-only or otherwise non-canonical values, it may be safer to trim the header value before checking emptiness to avoid unexpected exceptions fromfolly::to.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Now that `folly::to` will throw on malformed `Content-Length` or next-token headers, consider wrapping these conversions in a small helper that catches `folly::ConversionError` and rethrows with additional context (e.g., URL, header name, value) to make diagnosing bad upstream responses easier.
- For `contentLength`, you special-case the empty string to 0; if there is any possibility of whitespace-only or otherwise non-canonical values, it may be safer to trim the header value before checking emptiness to avoid unexpected exceptions from `folly::to`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
kewang1024
approved these changes
Feb 26, 2026
This was referenced Mar 31, 2026
15 tasks
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.
Summary:
Replace
atol()calls withfolly::to<>when parsing HTTP response headersin
PrestoExchangeSource.atol()silently returns 0 on empty/malformedinput and has undefined behavior on overflow.
folly::to<>throws on invalidinput, making failures explicit rather than silently degrading.
Two call sites fixed:
a missing Content-Length header is valid and should default to 0.
caller already checks for non-empty.
Summary by Sourcery
Bug Fixes: