Skip to content

Commit 98e4f01

Browse files
authored
Fix size on GenericMemory with non-Int Integer argument (#53161)
I found this through fuzzing. The nature of the issue indicates to me that this was untested, but coverage doesn't seem to have run for the past three months so I can't check, which is why I added an explicit test. I'm not sure `arrayops.jl` is the best place for tests related to `GenericMemory`, so feel free to suggest a better one. Co-authored-by: Sukera <Seelengrab@users.noreply.github.com>
1 parent f2e168a commit 98e4f01

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/genericmemory.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ size(a::GenericMemory, d::Int) =
2323
d < 1 ? error("dimension out of range") :
2424
d == 1 ? length(a) :
2525
1
26-
size(a::GenericMemory, d::Integer) = size(a, convert(d, Int))
26+
size(a::GenericMemory, d::Integer) = size(a, convert(Int, d))
2727
size(a::GenericMemory) = (length(a),)
2828

2929
IndexStyle(::Type{<:GenericMemory}) = IndexLinear()

test/arrayops.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,3 +3192,12 @@ end
31923192
@test_throws DimensionMismatch wrap(Array, memref2, 9)
31933193
@test_throws DimensionMismatch wrap(Array, memref2, 10)
31943194
end
3195+
3196+
@testset "Memory size" begin
3197+
len = 5
3198+
mem = Memory{Int}(undef, len)
3199+
@test size(mem, 1) == len
3200+
@test size(mem, 0x1) == len
3201+
@test size(mem, 2) == 1
3202+
@test size(mem, 0x2) == 1
3203+
end

0 commit comments

Comments
 (0)