Visitar URL original
Fix crashes found hunting the last open fuzzing record by youknowone · Pull Request #8524 · RustPython/RustPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f24691e
specialize: check the member descriptor's type before caching its slo…
youknowone Aug 14, 2026
40e67e1
socket: reserve recv()'s buffer fallibly
youknowone Aug 14, 2026
40a839b
types: count the __call__ and __get__ slot dispatches as recursion
youknowone Aug 14, 2026
bb744d6
typevar: show a ParamSpecArgs origin by its repr
youknowone Aug 14, 2026
7e4b96e
Do not hold a lock across a call back into Python
youknowone Aug 14, 2026
6e47646
Validate memoryview.cast() arguments and export negative strides corr…
youknowone Aug 14, 2026
2432fd7
Charge native recursion to the stack, not to the frame limit
youknowone Aug 14, 2026
02a6193
Report a size that cannot be allocated instead of aborting on it
youknowone Aug 14, 2026
ff52fe0
marshal: answer allow_code where a code object is written or read
youknowone Aug 14, 2026
d7cf971
Do not lock an object while running code that can reach it
youknowone Aug 14, 2026
61b989b
Stop asserting a pbkdf2 message that depends on the width of a C long
youknowone Aug 14, 2026
c9449a6
Publish and read the same pointer for a thread's top frame
youknowone Aug 15, 2026
ee782e0
Decide stop-the-world parking under the thread registry lock
youknowone Aug 15, 2026
fab2b3b
Keep an atexit callback alive while it is being compared
youknowone Aug 15, 2026
e3dcd8e
Hold atexit entries in PyRc rather than Arc
youknowone Aug 15, 2026
773ae23
Do not hold a buffer's storage while waiting for a peer
youknowone Aug 15, 2026
125d5aa
Do not hold a buffer's storage while waiting to hand it over
youknowone Aug 15, 2026
62ed618
Check select()'s descriptor limit while the sequence is walked
youknowone Aug 15, 2026
c65fe42
Bound native recursion where the C stack cannot be measured
youknowone Aug 15, 2026
00b64c3
Report the failure to allocate pbkdf2's key and Take.readinto's scratch
youknowone Aug 15, 2026
7c40cb9
Read the frozen-code tuple length as a signed length
youknowone Aug 15, 2026
ce43008
Make the snippets from the fuzzer sweep assert what they check
youknowone Aug 15, 2026
3d69690
Ask for a marshal container's room instead of assuming it
youknowone Aug 15, 2026
366ef3e
Compare the blocking-buffer snippet against something
youknowone Aug 15, 2026
ab0d4ff
Refuse array.frombytes() a source whose items are not bytes
youknowone Aug 15, 2026
7fad3b0
Tell apart the ways marshal data can be bad
youknowone Aug 15, 2026
a7f7021
Hash the collector's tables by address rather than by SipHash
youknowone Aug 16, 2026
691d6ca
Keep the collection's candidates and their counts in one table
youknowone Aug 16, 2026
3139b95
gc: collect referents into one buffer instead of a vector per object
youknowone Aug 16, 2026
dce42a3
memoryview and struct: match the checks and errors of the reference
youknowone Aug 16, 2026
5a5ba17
io: decide the readinto path by file type, not by seekability
youknowone Aug 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Validate memoryview.cast() arguments and export negative strides corr…
…ectly

cast() accepted any struct format and any shape element. A zero-size
format ('0s') and a 0 in the shape both reached a division by zero;
cast() now takes only a native single character format, optionally
'@'-prefixed, and shape elements that are ints greater than zero.

A view with a negative stride starts at its last item, so the bytes it
exported began there and its own offsets walked off the front of them.
Such a view now exports the whole underlying buffer with `start` folded
into the descriptor's offsets, and zip_eq() hands over a whole run only
when both sides are contiguous in the last dimension.

Assisted-by: Claude
Assisted-by: Codex:GPT-5
  • Loading branch information
youknowone committed Aug 16, 2026
commit 6e4764653a942732b60c161a905a57145697743f
14 changes: 13 additions & 1 deletion crates/vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,19 @@ impl PyMemoryView {
let mut dim_descriptor = Vec::with_capacity(shape_ndim);

for x in shape {
let x = usize::try_from_borrowed_object(vm, x)?;
let x = x
.downcast_ref::<PyInt>()
.ok_or_else(|| {
vm.new_type_error("memoryview.cast(): elements of shape must be integers")
})?
.try_to_primitive::<usize>(vm)
.ok()
.filter(|x| *x > 0)
.ok_or_else(|| {
vm.new_value_error(
"memoryview.cast(): elements of shape must be integers > 0",
)
})?;

if x > isize::MAX as usize / product_shape {
return Err(vm.new_value_error("memoryview.cast(): product(shape) > SSIZE_MAX"));
Expand Down
48 changes: 48 additions & 0 deletions extra_tests/snippets/builtin_memoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,51 @@ def test_fortran_contiguity():


test_fortran_contiguity()


def test_cast_arguments():
# cast() takes a native single character format, optionally '@'-prefixed;
# a zero-size format used to reach a division by zero.
assert memoryview(b"abcd").cast("@i").itemsize == 4
for fmt in ("0s", "4s", "<i", "", "ss"):
assert_raises(ValueError, lambda fmt=fmt: memoryview(b"abcd").cast(fmt))

# every element of shape is an int > 0; a 0 used to divide by zero while
# checking the product against SSIZE_MAX
for shape in ([0], [0, 4], [4, 0], [-1, 4], [0, 0]):
assert_raises(
ValueError, lambda shape=shape: memoryview(b"abcd").cast("B", shape)
)

class Index:
def __index__(self):
return 4

for shape in ([2.0, 2], [Index()], ["4"]):
assert_raises(
TypeError, lambda shape=shape: memoryview(b"abcd").cast("B", shape)
)

assert memoryview(b"abcd").cast("B", [True, 4]).tolist() == [[97, 98, 99, 100]]


test_cast_arguments()


def test_negative_stride():
# A reversed view starts at its last byte, so walking it from there runs
# off the front of the exported slice.
assert memoryview(b"dcba") == memoryview(b"abcd")[::-1]
assert memoryview(b"abcd")[::-1] == memoryview(b"dcba")
assert not memoryview(b"abcd") == memoryview(b"abcd")[::-1]

b = bytearray(b"____")
memoryview(b)[0:4] = memoryview(b"abcd")[::-1]
assert b == bytearray(b"dcba"), b

a = array.array("i", [1, 2, 3])
assert memoryview(array.array("i", [3, 2, 1])) == memoryview(a)[::-1]
assert memoryview(a)[::-1].tolist() == [3, 2, 1]


test_negative_stride()