Skip to content

Commit c816f7e

Browse files
committed
Assert that bytes_per_entry is in range(2,6)
1 parent 9ea88c0 commit c816f7e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Python/instrumentation.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,15 @@ get_line_delta(_PyCoLineInstrumentationData *line_data, int index)
343343
{
344344
uint8_t *ptr = &line_data->data[index*line_data->bytes_per_entry+1];
345345
uint32_t value = *ptr;
346+
assert(line_data->bytes_per_entry >= 2);
346347
if (line_data->bytes_per_entry > 2) {
347348
ptr++;
348349
value = (value << 8) | *ptr;
349350
if (line_data->bytes_per_entry > 3) {
350351
ptr++;
351352
value = (value << 8) | *ptr;
352353
if (line_data->bytes_per_entry > 4) {
354+
assert(line_data->bytes_per_entry == 5);
353355
ptr++;
354356
value = (value << 8) | *ptr;
355357
}
@@ -368,9 +370,11 @@ set_line_delta(_PyCoLineInstrumentationData *line_data, int index, int line_delt
368370
uint32_t adjusted = line_delta - NO_LINE;
369371
uint8_t *ptr = &line_data->data[index*line_data->bytes_per_entry+1];
370372
assert(adjusted < (1ULL << (line_data->bytes_per_entry*8)));
373+
assert(line_data->bytes_per_entry >= 2);
371374
if (line_data->bytes_per_entry > 2) {
372375
if (line_data->bytes_per_entry > 3) {
373376
if (line_data->bytes_per_entry > 4) {
377+
assert(line_data->bytes_per_entry == 5);
374378
*ptr = adjusted >> 24;
375379
ptr++;
376380
}

0 commit comments

Comments
 (0)