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
Refuse array.frombytes() a source whose items are not bytes
frombytes() reads its argument as bytes, but accepted any contiguous
buffer, so array("i").frombytes(memoryview(array("d", [1.0]))) appended a
double's bytes read as ints instead of raising. array_array_frombytes_impl
requires an itemsize of 1; ArgBytesLike now reports the itemsize so the
same check can be made here.

The BufferError that a resize meets while the array is exported also names
the array rather than repeating bytearray's wording.

stdlib_array.py's frombytes-of-itself case used typecode "i", where the
new check answers before the resize guard is reached; it uses "b" so the
guard is what refuses, and asserts the wider case separately.

Assisted-by: Claude
  • Loading branch information
youknowone committed Aug 16, 2026
commit ab0d4ff8c0ca49c639ba402ef9018cb611782ca3
11 changes: 11 additions & 0 deletions crates/stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ pub mod array {

#[pymethod]
fn frombytes(&self, b: ArgBytesLike, vm: &VirtualMachine) -> PyResult<()> {
// The source is read as bytes, so items of any other width would
// be reinterpreted rather than appended.
if b.itemsize() != 1 {
return Err(vm.new_type_error("a bytes-like object is required"));
}
let b = b.borrow_buf();
let itemsize = self.read().itemsize();
self._from_bytes(&b, itemsize, vm)
Expand Down Expand Up @@ -1472,6 +1477,12 @@ pub mod array {
// answered before the lock rather than by waiting on it.
(self.exports.load(atomic::Ordering::SeqCst) == 0).then(|| self.write())
}

fn try_resizable(&self, vm: &VirtualMachine) -> PyResult<Self::Resizable<'_>> {
self.try_resizable_opt().ok_or_else(|| {
vm.new_buffer_error("cannot resize an array that is exporting buffers")
})
}
}

#[pyattr]
Expand Down
8 changes: 8 additions & 0 deletions crates/vm/src/function/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ impl ArgBytesLike {
self.0.desc.len
}

/// The width of one item. Callers that read the buffer as bytes rather
/// than as whatever it holds have to ask, since a contiguous buffer of
/// wider items is contiguous all the same.
#[must_use]
pub const fn itemsize(&self) -> usize {
self.0.desc.itemsize
}

#[must_use]
pub const fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
19 changes: 10 additions & 9 deletions extra_tests/snippets/stdlib_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ def __index__(self):


def test_frombytes_of_itself():
# Resizing is refused while a buffer is exported, before any lock is taken
a = array("i", [1, 2, 3])
# Resizing is refused while a buffer is exported, before any lock is taken.
# The typecode is "b" so the view's items are bytes and the resize is what
# the call is refused for.
a = array("b", [1, 2, 3])
m = memoryview(a)
try:
with assert_raises(BufferError):
a.frombytes(m)
except (BufferError, TypeError):
# Refused either as a resize while exported or as a buffer whose
# items are not bytes; which one comes first is not the point here.
pass
else:
raise AssertionError("frombytes of its own exported buffer should be refused")
del m
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# A view of wider items is not a source of bytes at all.
wide = array("i", [1, 2, 3])
with assert_raises(TypeError):
wide.frombytes(memoryview(wide))