Skip to content

ext/mbstring: assert that mb_wchar_to_uuencode() pointer write is in bounds - #23955

Merged
DanielEScherzer merged 1 commit into
php:PHP-8.6from
DanielEScherzer:mbfilter-uuencode-in-bounds
Sep 28, 2026
Merged

DanielEScherzer merged 1 commit into
php:PHP-8.6from
DanielEScherzer:mbfilter-uuencode-in-bounds

Conversation

@DanielEScherzer

@DanielEScherzer DanielEScherzer commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Add a hardening assertion that when mb_wchar_to_uuencode() needs to update the length of the previous line, the location being written to is still part of the same overall output string (i.e. at or after the start of the buffer's str's value pointer, and before the end of the char array).

@alexdowad

Copy link
Copy Markdown
Contributor

This is fine, but you are only checking the pointer against a lower bound; should it also be checked against an upper bound?

@youkidearitai may also want to have a look.

@youkidearitai youkidearitai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand that len_byte address is must bigger than buf->str address.
LGTM

@DanielEScherzer

Copy link
Copy Markdown
Member Author

This is fine, but you are only checking the pointer against a lower bound; should it also be checked against an upper bound?

@youkidearitai may also want to have a look.

I mean, the pointer is created from subtracting from within the current allocation, so that shouldn't be an issue, but added

@DanielEScherzer
DanielEScherzer force-pushed the mbfilter-uuencode-in-bounds branch 2 times, most recently from 59e5548 to aa861a2 Compare September 28, 2026 22:30
@alexdowad

This comment was marked as resolved.

@alexdowad

This comment was marked as resolved.

…n bounds

Add a hardening assertion that when `mb_wchar_to_uuencode()` needs to update
the length of the previous line, the location being written to is still part of
the same overall output string (i.e. at or after the start of the buffer's
`str`'s value pointer, and before the end of the char array).
@DanielEScherzer
DanielEScherzer force-pushed the mbfilter-uuencode-in-bounds branch 2 times, most recently from aa861a2 to e0bf53d Compare September 28, 2026 23:13
@DanielEScherzer

Copy link
Copy Markdown
Member Author

Yeah I figured it out, buf->limit isn't synced by MB_CONVERT_BUF_ENSURE, only by MB_CONVERT_BUF_STORE

@alexdowad

Copy link
Copy Markdown
Contributor

Ah... so the write isn't really OOB, but the variable which we based the assertion on wasn't telling us the actually end of the allocated space?

@DanielEScherzer

Copy link
Copy Markdown
Member Author

Yes, so I switched the assertion to the correct limit

@alexdowad

Copy link
Copy Markdown
Contributor

If CI passes, let's go ahead and merge. @DanielEScherzer are you a committer?

@DanielEScherzer

Copy link
Copy Markdown
Member Author

If CI passes, let's go ahead and merge. @DanielEScherzer are you a committer?

Yes

@DanielEScherzer
DanielEScherzer merged commit 8906dc2 into php:PHP-8.6 Sep 28, 2026
18 checks passed
@DanielEScherzer
DanielEScherzer deleted the mbfilter-uuencode-in-bounds branch September 28, 2026 23:56
DanielEScherzer added a commit that referenced this pull request Sep 28, 2026
* PHP-8.6:
  ext/mbstring: assert that `mb_wchar_to_uuencode()` pointer write is in bounds (#23955)
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.

3 participants