Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f97d213

Browse files
committed
handle mmap_write_method
1 parent ba96163 commit f97d213

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix crash in :func:`mmap.read` on Windows when the underlying file operation raises errors.
1+
Fix crashes in :func:`mmap.read`, :func:`mmap.read_byte` and :func:`mmap.write` on Windows when the underlying file operation raises errors.

Modules/mmapmodule.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,15 @@ mmap_write_method(mmap_object *self,
486486
}
487487

488488
CHECK_VALID_OR_RELEASE(NULL, data);
489-
memcpy(&self->data[self->pos], data.buf, data.len);
490-
self->pos += data.len;
491-
PyBuffer_Release(&data);
492-
return PyLong_FromSsize_t(data.len);
489+
if (safe_memcpy(self->data + self->pos, data.buf, data.len) < 0) {
490+
PyBuffer_Release(&data);
491+
return NULL;
492+
}
493+
else {
494+
self->pos += data.len;
495+
PyBuffer_Release(&data);
496+
return PyLong_FromSsize_t(data.len);
497+
}
493498
}
494499

495500
static PyObject *

0 commit comments

Comments
 (0)