Skip to content

Ruby 3.4: Backport [Bug #21715]#15906

Merged
hsbt merged 1 commit intoruby:ruby_3_4from
hsbt:backport-21723-3-4
Jan 21, 2026
Merged

Ruby 3.4: Backport [Bug #21715]#15906
hsbt merged 1 commit intoruby:ruby_3_4from
hsbt:backport-21723-3-4

Conversation

@hsbt
Copy link
Member

@hsbt hsbt commented Jan 19, 2026

merge revision(s) d209e6f1c0a93ad3ce1cc64dd165a6b67672614d: [Backport #21715]

	[PATCH] search_nonascii(): Replace UB pointer cast with memcpy

	Casting a pointer to create an unaligned one is undefined behavior in C
	standards. Use memcpy to express the unaligned load instead to play by
	the rules.

	Practically, this yields the same binary output in many situations
	while fixing the crash in [Bug #21715].

	[PATCH] search_nonascii(): Replace UB pointer cast with memcpy

	Casting a pointer to create an unaligned one is undefined behavior in C
	standards. Use memcpy to express the unaligned load instead to play by
	the rules.

	Practically, this yields the same binary output in many situations
	while fixing the crash in [Bug #21715].
Copilot AI review requested due to automatic review settings January 19, 2026 02:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR backports a fix for Bug #21715 to Ruby 3.4, addressing undefined behavior in the search_nonascii() function. The issue involved casting pointers to create unaligned pointers, which is undefined behavior in C. The fix replaces unsafe pointer casting with memcpy to safely handle unaligned loads.

Changes:

  • Incremented the Ruby patchlevel from 72 to 73
  • Refactored search_nonascii() to use char pointer iteration with memcpy instead of uintptr_t pointer dereferencing
  • Eliminated undefined behavior while maintaining functionally equivalent code

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
version.h Incremented RUBY_PATCHLEVEL from 72 to 73 for the bug fix release
string.c Replaced unsafe unaligned pointer casts with memcpy-based loads in search_nonascii() function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hsbt hsbt merged commit 2bbc06e into ruby:ruby_3_4 Jan 21, 2026
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants