extmod/vfs_reader: Check that open() resulted in a file-like object.

That is, an object whose type defines the protocol slot.

Note that due to protocol confusion, a variant of the original crasher that
returned e.g., a machine.Pin instance could still lead to a crash (#17852).

Fixes issue #17841.

Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
Jeff Epler
2025-08-08 08:53:14 -05:00
committed by Damien George
parent adf6319884
commit 4b013ec3ff
3 changed files with 25 additions and 1 deletions

View File

@@ -83,7 +83,7 @@ void mp_reader_new_file(mp_reader_t *reader, qstr filename) {
};
mp_obj_t file = mp_vfs_open(MP_ARRAY_SIZE(args), &args[0], (mp_map_t *)&mp_const_empty_map);
const mp_stream_p_t *stream_p = mp_get_stream(file);
const mp_stream_p_t *stream_p = mp_get_stream_raise(file, MP_STREAM_OP_READ);
int errcode = 0;
#if MICROPY_VFS_ROM