Skip to content

Commit 9e8d182

Browse files
authored
Merge pull request #1480 from dhalbert/packinto-bug
struct.pack_into incorrect buffer size check
2 parents 92dd907 + 777408f commit 9e8d182

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

shared-module/struct/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size
124124
char fmt_type = get_fmt_type(&fmt);
125125
const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in);
126126

127-
if (p + total_sz != end_p) {
128-
mp_raise_msg_varg(&mp_type_RuntimeError, translate("unpack requires a buffer of %d bytes"), total_sz);
127+
if (p + total_sz > end_p) {
128+
mp_raise_RuntimeError(translate("buffer too small"));
129129
}
130130

131131
size_t i;

0 commit comments

Comments
 (0)