1268 Commits

Author SHA1 Message Date
nagachika
aa49c48608 merge revision(s) 88ffa9a3003c36e5c6001cca33e0bba2fcb37125: [Backport #22449]
[PATCH] [Bug #22449] Fix out-of-bounds in `Array#sample` when array modified

	Get the length after the conversion using `to_int` is complete.
2026-11-03 13:52:44 +09:00
nagachika
a1c96b6b0f merge revision(s) 3f6143715aa934b558f0b97462b42793c845e4d7: [Backport #22326]
[PATCH] Fix buffer overflow in Array#values_at

	Array#values_at can execute arbitrary code during execution which may
	modify the source array. This can cause a buffer overflow if the new length
	of the array has decreased. The following script crashes:

	    a = (0..100_000).to_a
	    obj = Object.new
	    obj.define_singleton_method(:begin) do
	      a.clear
	      0
	    end
	    obj.define_singleton_method(:end) { 10_000 }
	    obj.define_singleton_method(:exclude_end?) { false }
	    puts a.values_at(obj).length
2026-10-12 14:20:29 +09:00
nagachika
5721bcee5a merge revision(s) 1007084edc4251a778746ddbd80ac562526758d1: [Backport #9932]
[PATCH] Fix out-of-bounds in Array#permutation when array modified

	Calling to_int on the count may run Ruby code that modifies the array.
	This can cause an out-of-bounds in Array#permutation. For example, the
	following code crashes:

	    ary = (1..1_000).to_a
	    obj = Object.new
	    obj.define_singleton_method(:to_int) do
	      ary.replace(Array.new(5) { :x })
	      2
	    end
	    ary.permutation(obj) { }
2026-09-22 18:39:29 +09:00
nagachika
2a77c0f6f9 merge revision(s) 0c9f3f1e68e23a9ba2d7fdfdb86bd7ddcaf5e9d9: [Backport #22319]
[PATCH] Fix use-after-free when clearing array during zip

	[Bug #22319]

	Array#zip triggers an use-after-free it does not account for when the call
	to rb_check_array_type modifies the source array. The following script crashes:

	    a = (1..100_000).to_a
	    evil = Object.new; $a = a
	    def evil.to_ary; $a.clear; [1,2,3]; end
	    a.zip(evil)
2026-09-20 15:26:43 +09:00
nagachika
3ebd235fb6 merge revision(s) 5eeaedc3d3014a12264aa252c751e14ba0fc5507: [Backport #22318]
[PATCH] Fix use-after-free when clearing array during flatten

	[Bug #22318]

	Array#flatten triggers an use-after-free it does not account for when the
	call to rb_check_array_type modifies the source array. The following script
	crashes:

	    a = (1..100_000).to_a
	    $a = a
	    bad = Object.new
	    def bad.to_ary; $a.clear; [1,2,3]; end
	    a << bad
	    a.flatten
2026-09-20 15:26:43 +09:00
nagachika
1e1e90990c merge revision(s) 46c287e2ca39da63d5164e2b7227308a41554c9a: [Backport #22259]
[PATCH] Fix splicing an array that shares its buffer with a longer array

	Arrays sharing one buffer have the same data pointer, so rb_ary_splice()
	took `a` in `b = a.dup; b.pop; b.concat(a)` for `b` itself and rebased
	the source onto `b`'s shorter storage, copying uninitialized memory.
	Have the callers tell whether the replacement really is `ary`.

	[Bug #22259]

	Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-20 14:09:02 +09:00
Nobuyoshi Nakada
f8d0dcdfec [Bug #22092] Improve Array#sum when the initial value is a Float 2026-06-29 19:04:46 +09:00
tomoya ishida
477c505ac0
[DOC] Fix output examples containing old Hash#inspect format
The inspect format was intentionally changed as an outcome of
[Bug #20433] [ruby-core:118668], but some documentation update
was missing, as [Bug #20962] pointed out. Update some output
examples that clearly use Hash#inspect.
2024-12-18 12:08:15 -05:00
Kouhei Yanagita
25602421fb [DOC] Fix the block parameter name in Array#zip 2024-12-18 11:00:36 +09:00
Burdette Lamar
50a67820fb
[DOC] Change arg names from n to count (#12288) 2024-12-17 10:55:43 -05:00
Stan Lo
211857f48f Fix incorrect rdoc-ref links in array.rb 2024-12-13 18:09:39 -05:00
Jean Boussier
5335b140ab array.c: Remove unused rb_ary_verify function 2024-12-05 09:16:31 +01:00
Jean Boussier
bf225feb26 Fix an off by one in rb_ary_resize
When setting len to X we only need to grow the array
if len is bigger than capa. If they're equal we don't need to
increase capacity.
2024-12-04 22:46:02 +01:00
BurdetteLamar
d588a1c880 Correct order of listed methods 2024-12-02 15:28:53 -05:00
BurdetteLamar
9db056f2ea [DOC] Tweaks for Array 2024-11-20 10:40:49 -05:00
Takashi Kokubun
c9a5a71695 Move Array#select to Ruby
Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2024-11-13 12:27:26 -08:00
Jean byroot Boussier
6deeec5d45
Mark strings returned by Symbol#to_s as chilled (#12065)
* Use FL_USER0 for ELTS_SHARED

This makes space in RString for two bits for chilled strings.

* Mark strings returned by `Symbol#to_s` as chilled

[Feature #20350]

`STR_CHILLED` now spans on two user flags. If one bit is set it
marks a chilled string literal, if it's the other it marks a
`Symbol#to_s` chilled string.

Since it's not possible, and doesn't make much sense to include
debug info when `--debug-frozen-string-literal` is set, we can't
include allocation source, but we can safely include the symbol
name in the warning message, making it much easier to find the source
of the issue.

Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>

---------

Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-13 09:20:00 -05:00
BurdetteLamar
6a3eb384ce [DOC] Tweaks for array indexes 2024-11-11 11:23:00 -05:00
BurdetteLamar
071d0eca8e [DOC] Sort items in What's Here 2024-11-11 11:21:13 -05:00
BurdetteLamar
3ac5c05327 [DOC] Tweaks for Array#| 2024-11-11 09:43:30 -05:00
Burdette Lamar
72550d269e
[DOC] Doc for Array#zip (#11961) 2024-11-08 14:56:44 -05:00
Burdette Lamar
0193f6c288
[DOC] Doc for Array#values_at (#11960) 2024-11-06 22:19:42 -05:00
Takashi Kokubun
478e0fc710
YJIT: Replace Array#each only when YJIT is enabled (#11955)
* YJIT: Replace Array#each only when YJIT is enabled

* Add comments about BUILTIN_ATTR_C_TRACE

* Make Ruby Array#each available with --yjit as well

* Fix all paths that expect a C location

* Use method_basic_definition_p to detect patches

* Copy a comment about C_TRACE flag to compilers

* Rephrase a comment about add_yjit_hook

* Give METHOD_ENTRY_BASIC flag to Array#each

* Add --yjit-c-builtin option

* Allow inconsistent source_location in test-spec

* Refactor a check of BUILTIN_ATTR_C_TRACE

* Set METHOD_ENTRY_BASIC without touching vm->running
2024-11-04 11:14:28 -05:00
Burdette Lamar
a8f220ed90
[DOC] Tweaks for Array#uniq (#11949) 2024-10-28 10:05:49 -04:00
Burdette Lamar
05f894aba2
[DOC] Tweaks for Array#uniq! (#11950) 2024-10-25 10:52:22 -04:00
BurdetteLamar
2b98545646 [DOC] Tweaks for Array#union 2024-10-24 17:25:04 -04:00
BurdetteLamar
2078ba1984 [DOC] Tweaks for Array#transpose 2024-10-24 17:23:22 -04:00
Burdette Lamar
da82b84b55
[DOC] Tweaks for Array#inspect (#11935) 2024-10-22 15:20:58 -04:00
BurdetteLamar
00af6a3f04 [DOC] Tweaks for Array#to_h 2024-10-22 15:11:26 -04:00
Burdette Lamar
9cbf2f5fff
[DOC] Tweaks for Array#take_while (#11930) 2024-10-22 12:36:12 -04:00
Burdette Lamar
c837ae85d8
[DOC] Tweaks for Array#take (#11929) 2024-10-22 12:35:09 -04:00
BurdetteLamar
3a327e1c18 [DOC] Tweaks for Array#to_a 2024-10-22 11:24:32 -04:00
BurdetteLamar
d1b5c10957 [DOC] Tweaks for Array#sum 2024-10-18 11:12:54 -04:00
BurdetteLamar
161ea389af [DOC] Tweaks for Array#sort_by! 2024-10-18 11:08:43 -04:00
BurdetteLamar
c78e2987d4 [DOC] Tweaks for Array#sort! 2024-10-17 16:54:36 -04:00
Burdette Lamar
b1ffd9e959
[DOC] Tweaks for Array#sort (#11907) 2024-10-17 16:53:56 -04:00
Burdette Lamar
4621c9b815
[DOC] Tweaks for Array#slice! (#11902) 2024-10-16 14:52:34 -04:00
Burdette Lamar
81910a93ff
[DOC] Tweaks for Array#shift (#11886) 2024-10-12 10:36:29 -04:00
Burdette Lamar
77c7d88015
[DOC] Tweaks for Array#rotate! (#11875) 2024-10-11 11:30:52 -04:00
BurdetteLamar
c044777562 [DOC] Tweaks for Array#rotate 2024-10-11 11:13:55 -04:00
Burdette Lamar
c51947671e
[DOC] Tweaks for Array#repeated_permutation (#11873) 2024-10-11 11:12:12 -04:00
Burdette Lamar
09100508e6
[DOC] Tweaks for Array#reverse_each (#11855) 2024-10-10 16:03:40 -04:00
Burdette Lamar
71a59543a6
[DOC] Tweaks for Array#repeated_combination (#11839) 2024-10-10 11:15:17 -04:00
BurdetteLamar
f7fdf6cc36 [DOC] Tweaks for Array#rindex 2024-10-09 14:05:24 -04:00
BurdetteLamar
1962be267c [DOC] Tweaks for Array#reverse! 2024-10-09 14:02:37 -04:00
BurdetteLamar
377d022853 [DOC] Tweaks for Array#reverse 2024-10-09 13:54:54 -04:00
BurdetteLamar
65494d3cc6 [DOC] Tweaks for Array#reject! 2024-10-08 16:58:48 -04:00
BurdetteLamar
0469d169e2 [DOC] Tweaks for Array#reject 2024-10-08 16:57:19 -04:00
BurdetteLamar
015d9ebaec [DOC] Tweaks for Array#rassoc 2024-10-08 16:54:42 -04:00
Burdette Lamar
7c304e316f
[DOC] Tweaks for Array#product (#11823) 2024-10-08 13:37:19 -04:00