Skip to content

GH-50440: [C++][Gandiva] fix out-of-bounds read in set_error_for_date#50441

Open
Arawoof06 wants to merge 1 commit into
apache:mainfrom
Arawoof06:date-error-format-overread
Open

GH-50440: [C++][Gandiva] fix out-of-bounds read in set_error_for_date#50441
Arawoof06 wants to merge 1 commit into
apache:mainfrom
Arawoof06:date-error-format-overread

Conversation

@Arawoof06

@Arawoof06 Arawoof06 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

set_error_for_date formats the invalid-date/timestamp message with snprintf(error, size, "%s%s", msg, input), but input is a Gandiva string passed as pointer plus length and is not NUL-terminated, so the %s conversion scans past the length bytes looking for a terminator and over-reads the values buffer (past its end for the last value). It is reached from castDATE_utf8/castTIMESTAMP_utf8 on any invalid CAST(str AS DATE/TIMESTAMP) input. Switching to the bounded %.*s form with the explicit length keeps the read inside the string, matching every other error formatter in the precompiled sources.

What changes are included in this PR?

Use %.*s with length in set_error_for_date, which covers all of its call sites in both castDATE_utf8 and castTIMESTAMP_utf8.

Are these changes tested?

Yes. Added TestTime.TestCastDateInvalidUnterminated, which feeds an invalid date held in an exactly-sized heap buffer with no trailing NUL so the over-read trips AddressSanitizer, and checks the error string is bounded to the input length.

Are there any user-facing changes?

No.

This PR contains a "Critical Fix". It fixes a heap out-of-bounds read reachable from user-supplied CAST-to-date/timestamp input.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

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.

1 participant