Commit graph

82535 commits

Author SHA1 Message Date
nagachika
2b2ab1a67c 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-16 18:52:56 +09:00
nagachika
d213eb7f45 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-16 18:46:29 +09:00
nagachika
726bff43b4 merge revision(s) c224ca4fea: [Backport #21172]
Fix a race condition with interned strings sweeping.

	[Bug #21172]

	This fixes a rare CI failure.

	The timeline of the race condition is:

	- A `"foo" oid=1` string is interned.
	- `"foo" oid=1` is no longer referenced and will be swept in the future.
	- Another `"foo" oid=2` string is interned.
	- `register_fstring` finds `"foo" oid=1`, but since it is about to be swept,
	  removes it from `fstring_table` and insert `"foo" oid=2` instead.
	- `"foo" oid=1` is swept, since it has the `RSTRING_FSTR` flag,
	  a `st_delete` is issued in `fstring_table` which removes `"foo" oid=2`.

	I don't know how to reproduce this bug consistently in a single test
	case.
2025-03-16 18:02:45 +09:00
nagachika
1d3c19871d merge revision(s) 931ac960b6: [Backport #21159]
[Bug #21159] module names should not be modifiable
2025-03-16 15:39:32 +09:00
nagachika
da86a9959b 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.
2025-03-16 15:25:20 +09:00
nagachika
ac3f355fb3 Silently ignore keyword args for attr-asign method to cease segmentation fault. 2025-03-16 13:10:13 +09:00
nagachika
e860cb2267 merge revision(s) 91a10c0757: [Backport #21112]
Fix a typo in WeakKeyMap argument error

	[Bug #21112]
2025-03-08 18:21:16 +09:00
nagachika
fff5baf200 merge revision(s) 46b544c549, d3abee739f: [Backport #21095]
Prefer `uname -n` over `hostname`. (#12647)

	Add fallback for `hostname` if `uname` isn't available. (#12655)
2025-03-08 18:19:14 +09:00
nagachika
54dd27d89d 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-08 17:26:28 +09:00
nagachika
8274b8193e merge revision(s) f7059af50a: [Backport #21046]
Use no-inline version `rb_current_ec` on Arm64

	The TLS across .so issue seems related to Arm64, but not Darwin.
2025-03-08 17:23:15 +09:00
nagachika
56ba9041d9 merge revision(s) ae6bd3b49b, 966458199d, 966458199d: [Backport #20951]
[DOC] Tweak "Timezone Objects"

	- Make method descriptions plain pragraphs in each method.
	- Make "Argument" and "Returns" note-lists.

	[Bug #20951] [DOC] About UTC offset calculation after `utc_to_local`

	[Bug #20951] [DOC] About UTC offset calculation after `utc_to_local`
2025-03-08 17:03:20 +09:00
John Hawthorn
ef523984f0 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-08 16:43:58 +09:00
Hiroshi SHIBATA
ecb9f7ef37 Merge cgi-0.4.2 2025-03-08 16:27:22 +09:00
Hiroshi SHIBATA
e588271630 Merge uri-0.13.2 2025-03-08 16:27:22 +09:00
Nobuyoshi Nakada
188ff4d435 Name dependency checks job
And run on the latest ubuntu.
2025-03-05 16:09:35 -08:00
Hiroshi SHIBATA
9472548aa1 automerge needs windows results 2025-03-05 16:09:35 -08:00
Takashi Kokubun
c462deb482 Update actions/cache for ruby_3_3 2025-03-05 15:36:55 -08:00
Hiroshi SHIBATA
2e7f65acbd Skip VS2022 17.13.x build
see https://github.com/ruby/ruby/pull/12830
2025-02-28 16:43:01 +09:00
Takashi Kokubun
5eb08338ca Drop k0kubun from CODEOWNERS
The maintainers have been shifted to newer versions.
https://bugs.ruby-lang.org/issues/21136
2025-02-13 17:35:44 -08:00
nicholas a. evans
f8b9e2c06f
Bump net-imap to 0.4.19 for Ruby 3.3 (CVE-2025-25186) (#12732)
This update addresses CVE-2025-25186 (GHSA-7fc5-f82f-cx69).
2025-02-11 09:21:31 -08:00
Hiroshi SHIBATA
5b226fdb8d Support git ls-files ....split style for file list of gemspec 2025-02-10 08:29:08 -08:00
Hiroshi SHIBATA
84b60a03cd Bump up net-smtp-0.5.1 2025-02-10 08:29:08 -08:00
Hiroshi SHIBATA
da75893dbe Bump up actions/upload-artifact-4.4.1 2025-02-06 09:49:44 +09:00
Takashi Kokubun
be31f993d7 v3.3.7 2025-01-14 23:22:35 -08:00
Takashi Kokubun
b6affbca88 Skip an unstable test due to a Ractor assertion 2025-01-14 21:25:34 -08:00
Takashi Kokubun
e9f479d871 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.

Co-Authored-By: Alan Wu <alanwu@ruby-lang.org>
2025-01-14 21:16:37 -08:00
Takashi Kokubun
02bcfb42be 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-14 21:13:29 -08:00
Takashi Kokubun
7b9caf19ba 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-14 18:00:02 -08:00
Takashi Kokubun
12a0807965 merge revision(s) 8034e9c3d0: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
2025-01-14 17:59:12 -08:00
Takashi Kokubun
0d6459249d merge revision(s) 19c39e4cfa: [Backport #20984]
[Bug #20984] ENV.inspect should be encoding aware
2025-01-14 17:58:17 -08:00
Takashi Kokubun
3a986b47cb 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-14 17:56:25 -08:00
Takashi Kokubun
299455be99 merge revision(s) 92dd9734a9: [Backport #20950]
Fix use-after-free in ep in Proc#dup for ifunc procs

	[Bug #20950]

	ifunc proc has the ep allocated in the cfunc_proc_t which is the data of
	the TypedData object. If an ifunc proc is duplicated, the ep points to
	the ep of the source object. If the source object is freed, then the ep
	of the duplicated object now points to a freed memory region. If we try
	to use the ep we could crash.

	For example, the following script crashes:

	    p = { a: 1 }.to_proc
	    100.times do
	      p = p.dup
	      GC.start
	      p.call
	    rescue ArgumentError
	    end

	This commit changes ifunc proc to also duplicate the ep when it is duplicated.
2025-01-14 17:54:19 -08:00
Takashi Kokubun
00147cbab5 merge revision(s) e90b447655: [Backport #20924]
[Bug #20924] Fix reading with delimiter in wide character encodings
2025-01-14 17:53:38 -08:00
Takashi Kokubun
1b1c6e6758 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>
2025-01-14 17:52:11 -08:00
Takashi Kokubun
745fe4cf7e 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`.
2025-01-14 17:51:27 -08:00
Takashi Kokubun
1e48631e0f merge revision(s) 02b70256b5, 6b4f8945d6: [Backport #20909]
Check negative integer underflow

	Many of Oniguruma functions need valid encoding strings
2025-01-14 17:50:24 -08:00
Takashi Kokubun
8506fdfb4a 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]
2025-01-14 17:48:57 -08:00
Takashi Kokubun
f19831a15d merge revision(s) a8c2d5e7be: [Backport #20907]
Ensure fiber scheduler re-acquires mutex when interrupted from sleep. (#12158)

	[Bug #20907]
2025-01-14 17:47:41 -08:00
Takashi Kokubun
1ec258ab70 merge revision(s) d71be7274b: [Backport #20873]
[Bug #20873] Consider `-FIXNUM_MIN` overflow

	`-FIXNUM_MIN` is usually greater than `FIXNUM_MAX` on platforms using
	two's complement representation.
2025-01-14 17:42:54 -08:00
Takashi Kokubun
42f043c189 merge revision(s) 56ecc243e2: [Backport #20868]
[Bug #20868] Fix Method#hash to not change after compaction

	The hash value of a Method must remain constant after a compaction, otherwise
	it may not work as the key in a hash table.

	For example:

	    def a; end

	    # Need this method here because otherwise the iseq may be on the C stack
	    # which would get pinned and not move during compaction
	    def get_hash
	      method(:a).hash
	    end

	    puts get_hash # => 2993401401091578131

	    GC.verify_compaction_references(expand_heap: true, toward: :empty)

	    puts get_hash # => -2162775864511574135
2025-01-14 17:40:39 -08:00
Takashi Kokubun
2330146397 merge revision(s) 773d140f65: [Backport #20787]
[Bug #20787] Check the separator in `IO#readline` as well as 3.2
2025-01-14 17:38:34 -08:00
Hiroshi SHIBATA
732ee20a02 Bump up actions/checkout-4.2.2 2024-12-03 11:08:37 +09:00
Hiroshi SHIBATA
7ff601aea0 Lock json-schema-5.1.0 for using pure ruby version 2024-12-03 11:08:37 +09:00
Hiroshi SHIBATA
c53d12ee70 Revert "Skip tests that suddenly started failing for MinGW"
This reverts commit f72eb702f2.
2024-11-20 10:18:27 +09:00
Nobuyoshi Nakada
da00816957 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-20 10:18:27 +09:00
Nobuyoshi Nakada
7e2789415b Make MUNICODE_FLAG simply expanded
It is not expected that `target_os` will change going forward.
2024-11-20 10:18:27 +09:00
Daisuke Fujimura (fd0)
b4afc2b25f EXE_LDFLAGS uses the same MUNICODE_FLAG 2024-11-20 10:18:27 +09:00
Daisuke Fujimura (fd0)
b7475e2ac3 -municode is available for MinGW-w64 targets only 2024-11-20 10:18:27 +09:00
Nobuyoshi Nakada
b3a1fc146c Use wide character startup
Mingw crt-git 12.0.0.r369.g0d4221712-1 now prohibits "command line
contains characters that are not supported in the active code page".
0d42217123/

Already Ruby builds `argv` in `rb_w32_sysinit`, instead of mswin- or
mingw-made `argv`.  Just bypass the conversion in mingw crt.
2024-11-20 10:18:27 +09:00
Nobuyoshi Nakada
792826d5f4 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-20 10:18:27 +09:00