Skip to content

GH-51005: [C++] Fix over-read in UriFromAbsolutePath posix branch - #51006

Merged
pitrou merged 1 commit into
apache:mainfrom
Arawoof06:uri-abspath-nul-terminate
Aug 26, 2026
Merged

GH-51005: [C++] Fix over-read in UriFromAbsolutePath posix branch#51006
pitrou merged 1 commit into
apache:mainfrom
Arawoof06:uri-abspath-nul-terminate

Conversation

@Arawoof06

Copy link
Copy Markdown
Contributor

Rationale for this change

the posix branch of UriFromAbsolutePath passes path.data() from a std::string_view straight into uriUnixFilenameToUriStringA, which scans its argument as a nul-terminated c string. a string_view is not required to be nul-terminated, so a view backed by a larger buffer makes the vendored routine read past the end of the view, and because out is sized from path.length() a longer run also writes past out. the windows branch just above already sidesteps this by copying into a std::string first.

What changes are included in this PR?

copy the view into a std::string on the posix branch before the call and size the output from that copy, mirroring the windows branch.

Are these changes tested?

yes. UriFromAbsolutePath.NonNulTerminatedView passes a prefix view of a longer buffer; before the change the conversion consumed the trailing bytes and returned file:///tmp/foo%20and%20more%20b..., after it returns file:///tmp/foo. the existing UriFromAbsolutePath.Basics still passes.

Are there any user-facing changes?

no.

This PR contains a "Critical Fix". it fixes a heap out-of-bounds read (and possible write) reachable through the public UriFromAbsolutePath entry point when the caller passes a view that is not nul-terminated.

the posix branch of UriFromAbsolutePath hands path.data() from a std::string_view straight to uriUnixFilenameToUriStringA, which scans its argument as a nul-terminated c string. a view is not required to be nul-terminated, so one backed by a larger buffer makes the routine read past the view, and because out was sized from path.length() a longer run also writes past out. the windows branch above already sidesteps this by copying into a std::string first, so do the same on posix and pass the terminated buffer.
@Arawoof06
Arawoof06 requested a review from pitrou as a code owner August 26, 2026 09:24
@github-actions github-actions Bot added the awaiting review Awaiting review label Aug 26, 2026
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51005 has been automatically assigned in GitHub to PR creator.

@pitrou pitrou changed the title GH-51005: [C++] fix over-read in UriFromAbsolutePath posix branch GH-51005: [C++] Fix over-read in UriFromAbsolutePath posix branch Aug 26, 2026

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch @Arawoof06 . Thanks a lot for fixing this!

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Aug 26, 2026
@pitrou
pitrou merged commit 6cd5e7e into apache:main Aug 26, 2026
83 of 85 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants