Commit graph

75943 commits

Author SHA1 Message Date
Hiroshi SHIBATA
13f495dc2c
bump teeny 2025-03-26 13:18:02 +09:00
David Rodríguez
a56c2fb375 [rubygems/rubygems] Support git 2.49
One error message that we parse is now slightly different.

758528791d
2025-03-24 13:24:21 +09:00
Hiroshi SHIBATA
469a0a4a08 merge revision(s) da4464b824: [Backport #19426]
[Bug #19426] Fix endless `Range#step` with `#succ` method
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
998c26cd28 merge revision(s) 79eb75a8dd: [Backport #20025]
[Bug #20025] Check if upper/lower before fallback to case-folding
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
774e3f0003 merge revision(s) 08b3a45bc9: [Backport #21180]
Push a real iseq in rb_vm_push_frame_fname()

	Previously, vm_make_env_each() (used during proc
	creation and for the debug inspector C API) picked up the
	non-GC-allocated iseq that rb_vm_push_frame_fname() creates,
	which led to a SEGV when the GC tried to mark the non GC object.

	Put a real iseq imemo instead. Speed should be about the same since
	the old code also did a imemo allocation and a malloc allocation.

	Real iseq allows ironing out the special-casing of dummy frames in
	rb_execution_context_mark() and rb_execution_context_update(). A check
	is added to RubyVM::ISeq#eval, though, to stop attempts to run dummy
	iseqs.

	[Bug #21180]

	Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
f89a334b55 merge revision(s) bccec7fb46, 5f8ebcada0, e13575bb79, 4adcfc8cd7: [Backport #19584]
Fix crash in rb_gc_register_address

	[Bug #19584]

	Some C extensions pass a pointer to a global variable to
	rb_gc_register_address. However, if a GC is triggered inside of
	rb_gc_register_address, then the object could get swept since it does
	not exist on the stack.

	[Bug #19584] Register global variable address before assignment

	[Bug #19584] Register global variables before assignment

	[Bug #19584] [DOC] Tweek description of `rb_gc_register_address`
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
2c49513291 it is not working with Ruby 3.2 2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
64d93539e7 Merge strscan-3.0.7 2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
30379fa1e2 Merge strscan-3.0.6 2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
6dd8bd0d90 merge revision(s) f423f6e10c: [Backport #21131]
Ensure IO.copy_stream buffer is an independent string

	Otherwise, changes to the buffer by the destination write method
	could result in data changing for supposedly independent strings.

	Fixes [Bug #21131]
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
1c9af6c10f merge revision(s) d4a1a2780c: [Backport #21032]
rb_feature_p: skip `get_expanded_load_path` for absolute paths

	Ref: https://github.com/fxn/zeitwerk/pull/308

	```ruby
	require 'benchmark'

	$LOAD_PATH << 'relative-path'

	autoload :FOO, '/tmp/foo.rb'

	puts Benchmark.realtime {
	  500_000.times do
	    Object.autoload?(:FOO)
	  end
	}
	```

	The above script takes 2.5 seconds on `master`, and only
	50ms on this branch.

	When we're looking for a feature with an absolute path, we don't
	need to call the expensive `get_expanded_load_path`.
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
0ef3411b98 merge revision(s) 6473903082: [Backport #18257]
[Bug #18257] Register the class path of FrozenCore to mark

	ICLASS does not have the path usually, so it needs to be registered
	separately.
2025-03-13 14:27:06 +09:00
Hiroshi SHIBATA
f7ec9546ee
merge revision(s) 3f07bc76ff, 34098b669c: [Backport #21144]
[Bug #21144] Win32: Use Windows time zone ID if TZ is not set

	If the TZ environment variable is not set, the time zone names
	retrieved from the system are localized for UI display and may vary
	across editions and language packs for the same time zone.
	Use the time zone IDs that are invariant across environments instead.

	[Bug #21144] Win32: Convert the time zone name to the current locale

	The Windows time zone IDs provided by Microsoft as of 24H1 are ASCII
	only all, but the API itself is not impossible to set non-ASCII key
	name.  Prefer the current locale encoding for now until we move to
	UTF-8 including environment variables and command line arguments.
2025-03-10 15:48:58 +09:00
Hiroshi SHIBATA
d635eb5156
Update the latest version of redmine-backporter.rb and merger.rb 2025-03-10 15:48:27 +09:00
John Hawthorn
bb6b3c98dc Replace tombstone when converting AR to ST hash
[Bug #21170]

st_table reserves -1 as a special hash value to indicate that an entry
has been deleted. So that that's a valid value to be returned from the
hash function, do_hash replaces -1 with 0 so that it is not mistaken for
the sentinel.

Previously, when upgrading an AR table to an ST table,
rb_st_add_direct_with_hash was used which did not perform the same
conversion, this could lead to a hash in a broken state where one if its
entries which was supposed to exist being marked as a tombstone.

The hash could then become further corrupted when the ST table required
resizing as the falsely tombstoned entry would be skipped but it would
be counted in num entries, leading to an uninitialized entry at index
15.

In most cases this will be really rare, unless using a very poorly
implemented custom hash function.

This also adds two debug assertions, one that st_add_direct_with_hash
does not receive the reserved hash value, and a second in
rebuild_table_with, which ensures that after we rebuild/compact a table
it contains the expected number of elements.

Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2025-03-06 11:05:43 +09:00
Hiroshi SHIBATA
977d711ba1 Update actions/checkout and actions/cache and others 2025-03-06 09:52:09 +09:00
Hiroshi SHIBATA
d6517a3dde Skip VS2022 17.13.x build
see https://github.com/ruby/ruby/pull/12830
2025-02-28 17:02:07 +09:00
Hiroshi SHIBATA
98fc456891
merge revision(s) 2b6fc9ea72: [Backport #21092]
[Bug #21092] Fallback variables after execonf has done

	When reading from a dummy makefile, the global variables initialized
	in `init_mkmf` may not be overridden.
	---
	 ext/extmk.rb | 6 +++---
	 1 file changed, 3 insertions(+), 3 deletions(-)
2025-02-28 15:06:44 +09:00
Hiroshi SHIBATA
9e5d68f03f Merge cgi-0.3.7 2025-02-26 19:19:19 +09:00
Hiroshi SHIBATA
946907f218 Merge uri-0.12.4 2025-02-26 19:19:19 +09:00
nick evans
164aaf6a47 Bump net-imap to 0.3.8 for Ruby 3.2 (CVE-2025-25186)
This update addresses CVE-2025-25186 (GHSA-7fc5-f82f-cx69).
2025-02-14 11:50:48 +09:00
nagachika
02ec315244 bump teeny 2025-02-04 20:33:29 +09:00
nagachika
7c0c2df9b4 merge revision(s) dd80d9b089: [Backport #20997]
YJIT: Filter `&` calls from specialized C method codegen

	Evident with the crash reported in [Bug #20997], the C replacement
	codegen functions aren't authored to handle block arguments (nor
	should they because the extra code from the complexity defeats
	optimization). Filter sites with VM_CALL_ARGS_BLOCKARG.
2025-01-25 14:51:31 +09:00
nagachika
97243cc9c7 merge revision(s) 04ec077946: [Backport #21038]
Preserve `errno` in `rb_fiber_scheduler_unblock`. (#12576)

	[Bug #21038]

	Co-authored-by: Julian Scheid <julians37@gmail.com>
2025-01-25 14:39:22 +09:00
nagachika
f9adaab928 merge revision(s) e0d600ec19: [Backport #21012]
Avoid opt_aset_with optimization inside multiple assignment

	Previously, since the opt_aset_with optimization was introduced,
	use of the opt_aset_with optimization inside multiple assignment
	would result in a segfault or incorrect instructions.

	Fixes [Bug #21012]

	Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2025-01-25 14:37:41 +09:00
nagachika
845763fdf3 merge revision(s) b176d4f52e: [Backport #21008]
[Bug #21008] Normalize before sum to float

	After switching to `Float`-mode when summing `Numeric` objects,
	normalization for `Float` is still needed.
2025-01-11 15:32:49 +09:00
nagachika
f150d67b7d merge revision(s) 8034e9c3d0: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
2025-01-11 15:30:06 +09:00
nagachika
4e59c10646 merge revision(s) 19c39e4cfa, d78ff6a767: [Backport #20984]
[Bug #20984] ENV.inspect should be encoding aware

	[Bug #20984] Fix test with locale encoding
2025-01-11 15:28:05 +09:00
nagachika
1d57924d69 merge revision(s) a1758fbd7f:
Crash when malloc during GC

	This feature was introduced in commit 2ccf6e5, but I realized that
	using rb_warn is a bad idea because it allocates objects, which causes
	a different crash ("object allocation during garbage collection phase").
	We should just hard crash here instead.
2024-12-21 13:31:11 +09:00
nagachika
3110d5c8ab merge revision(s) e90b447655: [Backport #20924]
[Bug #20924] Fix reading with delimiter in wide character encodings
2024-12-15 16:18:43 +09:00
nagachika
59254caff0 merge revision(s) 055613fd86: [Backport #20447]
Fix pointer incompatiblity

	Since the subsecond part is discarded, WIDEVAL to VALUE conversion is
	needed.
2024-12-15 15:31:58 +09:00
nagachika
303a83d35c merge revision(s) 660b995365: [Backport #20915]
[Bug #20915] Fix SEGV with `TracePoint#parameters` and aliased C method

	The following snippet results with a SEGV:

	```ruby
	C = Class.new do
	  alias_method :new_to_s, :to_s
	end

	TracePoint.new(:c_call, &:parameters).enable { C.new.new_to_s }
	```

	at MRI 3.3.6 and ruby 3.4.0dev

	The root cause of the issue lies in the `rb_tracearg_parameters` function
	within the `RUBY_EVENT_C_RETURN` branch. Specifically, when the invoked
	method is an alias for a C function,
	`rb_method_entry_without_refinements(..., trace_arg->called_id, ...)`
	may return NULL. In that case we can fallback to `trace_arg->id`.
2024-12-15 15:28:25 +09:00
nagachika
d78e1a4133 merge revision(s) f65a6c090c: [Backport #20921]
Fix use-after-free in constant cache

	[Bug #20921]

	When we create a cache entry for a constant, the following sequence of
	events could happen:

	- vm_track_constant_cache is called to insert a constant cache.
	- In vm_track_constant_cache, we first look up the ST table for the ID
	  of the constant. Assume the ST table exists because another iseq also
	  holds a cache entry for this ID.
	- We then insert into this ST table with the iseq_inline_constant_cache.
	- However, while inserting into this ST table, it allocates memory, which
	  could trigger a GC. Assume that it does trigger a GC.
	- The GC frees the one and only other iseq that holds a cache entry for
	  this ID.
	- In remove_from_constant_cache, it will appear that the ST table is now
	  empty because there are no more iseq with cache entries for this ID, so
	  we free the ST table.
	- We complete GC and continue our st_insert. However, this ST table has
	  been freed so we now have a use-after-free.

	This issue is very hard to reproduce, because it requires that the GC runs
	at a very specific time. However, we can make it show up by applying this
	patch which runs GC right before the st_insert to mimic the st_insert
	triggering a GC:

	    diff --git a/vm_insnhelper.c b/vm_insnhelper.c
	    index 3cb23f06f0..a93998136a 100644
	    --- a/vm_insnhelper.c
	    +++ b/vm_insnhelper.c
	    @@ -6338,6 +6338,10 @@ vm_track_constant_cache(ID id, void *ic)
	            rb_id_table_insert(const_cache, id, (VALUE)ics);
	        }

	    +    if (id == rb_intern("MyConstant")) rb_gc();
	    +
	        st_insert(ics, (st_data_t) ic, (st_data_t) Qtrue);
	    }

	And if we run this script:

	    Object.const_set("MyConstant", "Hello!")

	    my_proc = eval("-> { MyConstant }")
	    my_proc.call

	    my_proc = eval("-> { MyConstant }")
	    my_proc.call

	We can see that ASAN outputs a use-after-free error:

	    ==36540==ERROR: AddressSanitizer: heap-use-after-free on address 0x606000049528 at pc 0x000102f3ceac bp 0x00016d607a70 sp 0x00016d607a68
	    READ of size 8 at 0x606000049528 thread T0
	        #0 0x102f3cea8 in do_hash st.c:321
	        #1 0x102f3ddd0 in rb_st_insert st.c:1132
	        #2 0x103140700 in vm_track_constant_cache vm_insnhelper.c:6345
	        #3 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #4 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #5 0x1030bc1e0 in vm_exec_core insns.def:263
	        #6 0x1030b55fc in rb_vm_exec vm.c:2585
	        #7 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #8 0x102a82588 in rb_ec_exec_node eval.c:281
	        #9 0x102a81fe0 in ruby_run_node eval.c:319
	        #10 0x1027f3db4 in rb_main main.c:43
	        #11 0x1027f3bd4 in main main.c:68
	        #12 0x183900270  (<unknown module>)

	    0x606000049528 is located 8 bytes inside of 56-byte region [0x606000049520,0x606000049558)
	    freed by thread T0 here:
	        #0 0x104174d40 in free+0x98 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x54d40)
	        #1 0x102ada89c in rb_gc_impl_free default.c:8183
	        #2 0x102ada7dc in ruby_sized_xfree gc.c:4507
	        #3 0x102ac4d34 in ruby_xfree gc.c:4518
	        #4 0x102f3cb34 in rb_st_free_table st.c:663
	        #5 0x102bd52d8 in remove_from_constant_cache iseq.c:119
	        #6 0x102bbe2cc in iseq_clear_ic_references iseq.c:153
	        #7 0x102bbd2a0 in rb_iseq_free iseq.c:166
	        #8 0x102b32ed0 in rb_imemo_free imemo.c:564
	        #9 0x102ac4b44 in rb_gc_obj_free gc.c:1407
	        #10 0x102af4290 in gc_sweep_plane default.c:3546
	        #11 0x102af3bdc in gc_sweep_page default.c:3634
	        #12 0x102aeb140 in gc_sweep_step default.c:3906
	        #13 0x102aeadf0 in gc_sweep_rest default.c:3978
	        #14 0x102ae4714 in gc_sweep default.c:4155
	        #15 0x102af8474 in gc_start default.c:6484
	        #16 0x102afbe30 in garbage_collect default.c:6363
	        #17 0x102ad37f0 in rb_gc_impl_start default.c:6816
	        #18 0x102ad3634 in rb_gc gc.c:3624
	        #19 0x1031406ec in vm_track_constant_cache vm_insnhelper.c:6342
	        #20 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #21 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #22 0x1030bc1e0 in vm_exec_core insns.def:263
	        #23 0x1030b55fc in rb_vm_exec vm.c:2585
	        #24 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #25 0x102a82588 in rb_ec_exec_node eval.c:281
	        #26 0x102a81fe0 in ruby_run_node eval.c:319
	        #27 0x1027f3db4 in rb_main main.c:43
	        #28 0x1027f3bd4 in main main.c:68
	        #29 0x183900270  (<unknown module>)

	    previously allocated by thread T0 here:
	        #0 0x104174c04 in malloc+0x94 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x54c04)
	        #1 0x102ada0ec in rb_gc_impl_malloc default.c:8198
	        #2 0x102acee44 in ruby_xmalloc gc.c:4438
	        #3 0x102f3c85c in rb_st_init_table_with_size st.c:571
	        #4 0x102f3c900 in rb_st_init_table st.c:600
	        #5 0x102f3c920 in rb_st_init_numtable st.c:608
	        #6 0x103140698 in vm_track_constant_cache vm_insnhelper.c:6337
	        #7 0x1030b91d8 in vm_ic_track_const_chain vm_insnhelper.c:6356
	        #8 0x1030b8cf8 in rb_vm_opt_getconstant_path vm_insnhelper.c:6424
	        #9 0x1030bc1e0 in vm_exec_core insns.def:263
	        #10 0x1030b55fc in rb_vm_exec vm.c:2585
	        #11 0x1030fe0ac in rb_iseq_eval_main vm.c:2851
	        #12 0x102a82588 in rb_ec_exec_node eval.c:281
	        #13 0x102a81fe0 in ruby_run_node eval.c:319
	        #14 0x1027f3db4 in rb_main main.c:43
	        #15 0x1027f3bd4 in main main.c:68
	        #16 0x183900270  (<unknown module>)

	This commit fixes this bug by adding a inserting_constant_cache_id field
	to the VM, which stores the ID that is currently being inserted and, in
	remove_from_constant_cache, we don't free the ST table for ID equal to
	this one.

	Co-Authored-By: Alan Wu <alanwu@ruby-lang.org>
2024-12-15 15:26:55 +09:00
Hiroshi SHIBATA
1ae2b16d00 Lock json-schema-5.1.0 for using pure ruby version 2024-12-03 11:04:23 +09:00
nagachika
937319126a merge revision(s) 02b70256b5, 6b4f8945d6: [Backport #20909]
Check negative integer underflow

	Many of Oniguruma functions need valid encoding strings
2024-11-30 18:34:32 +09:00
nagachika
87249cbddb merge revision(s) a8c2d5e7be: [Backport #20907]
Ensure fiber scheduler re-acquires mutex when interrupted from sleep. (#12158)

	[Bug #20907]
2024-11-30 14:31:31 +09:00
nagachika
bb065f0844 merge revision(s) 3b7892b6e4: [Backport #20871]
Fix a bug in rb_include_module that stops nested inclusion into module subclasses

	This bug was present since the code was originally added by me
	in 3556a834a2.

	Fixes [Bug #20871]
2024-11-30 14:29:18 +09:00
nagachika
1fc0895971 merge revision(s) 0d4de0f4b1: [Backport #20898]
wasm: align fiber stack pointer to 16 bytes

	In WebAssembly C ABI, the linear stack pointer must be always aligned
	to 16 bytes like other archs.
	The misaligned stack pointer causes some weird memory corruption since
	compiler assumes the aligned stack pointer.
2024-11-30 14:25:56 +09:00
Hiroshi SHIBATA
d3098d2068 Removed extra assertions for Ruby 3.2 2024-11-22 08:06:01 +09:00
KJ Tsanaktsidis
9e1a78059d Fix flaky "Expected 499 to be >= 500" assertion in test_gc_compact.rb
There have been some sproradically flaky tests related to GC compaction,
which fail with:

  1) Failure:
TestGCCompact#test_moving_hashes_down_size_pools [/test/ruby/test_gc_compact.rb:442]:
Expected 499 to be >= 500.

What's happening here, is that, _sometimes_, depending on very unlucky
combinations of machine things, one of the expected-to-be-moved hashes
might be found on the machine stack during GC, and thus pinned.

One factor which seems to make this _more_ likely is that GCC 11 on
Ubuntu 22.04 seems to want to allocate 440 bytes of stack space for
`gc_start`, which is much more than it actually uses on the common code
path. The result is that there are some 50-odd VALUE-sized cells "live"
on the stack which may well contain valid heap pointers from previous
function calls, and will need to be pinned.

This is, of course, totally normal and expected; Ruby's GC is
conservative and if there is the possibility that a VALUE might be live
on the machine stack, it can't be moved. However, it does make these
tests flaky.

This commit "fixes" the tests by performing the work in a fiber; the
fiber goes out of scope and should be collected by the call to
verify_compaction_references, so there should be no references to the
to-be-moved objects floating around on the machine stack.

Fixes [#20021]
2024-11-22 08:06:01 +09:00
Peter Zhu
9aa313f2f8 Assert that at least one element has been embedded
It's not guaranteed that the first element will always be embedded.
2024-11-22 08:06:01 +09:00
Peter Zhu
c692229197 Assert that resizing arrays will re-embed them 2024-11-22 08:06:01 +09:00
Peter Zhu
605592b9be Assert that resizing objects will re-embed them 2024-11-22 08:06:01 +09:00
Matt Valentine-House
ed41225edd Fix Error in GC Compaction specs
Previously if any of the tests that move objects between size pools
failed to move anything, then the call to stats.dig would return `nil`
which would then cause assert_operator to error.

This should be a test Failure, rather than an Error so this commit uses
a default value of 0 if stats.dig fails to find a key.

Also refactor object movement tests to use stats.dig, rather than :[]
2024-11-22 08:06:01 +09:00
Nobuyoshi Nakada
2861aa22d0 Make rb_ec_set_vm_stack conformant to the C++11 requirement
Https://learn.microsoft.com/en-us/cpp/build/reference/zc-inline-remove-unreferenced-comdat?view=msvc-140
> If `/Zc:inline` is specified, the compiler enforces the C++11
> requirement that all functions declared inline must have a definition
> available in the same translation unit if they're used.
2024-11-19 19:31:46 +09:00
Nobuyoshi Nakada
0c8a3181c0 Win32: Remove unreferenced COMDAT from object files
Windows 11 SDK Version 10.0.26100.0 introduced a new internal inline
function in ucrt/corecrt_math.h.  Even it appears in object files and
will be included in the DEF file, it will be removed from the DLL and
result in a linker error.
2024-11-19 19:31:46 +09:00
Nobuyoshi Nakada
3d6fe67f42 Win32: Expose wchar main routine only
Warned if both of `main` and `wmain` are exposed:
```
LINK : warning LNK4067: ambiguous entry point; selected 'mainCRTStartup'
```
2024-11-19 19:31:46 +09:00
Nobuyoshi Nakada
e5b29c89a0 Make MUNICODE_FLAG simply expanded
It is not expected that `target_os` will change going forward.
2024-11-19 19:31:46 +09:00
Daisuke Fujimura (fd0)
104ba2edfb EXE_LDFLAGS uses the same MUNICODE_FLAG 2024-11-19 19:31:46 +09:00
Daisuke Fujimura (fd0)
fba0b48c89 -municode is available for MinGW-w64 targets only 2024-11-19 19:31:46 +09:00