gh-149009: Validate thread_count in profiling.sampling binary reader (#149147)

This commit is contained in:
Maurycy Pawłowski-Wieroński 2026-05-05 02:50:06 +02:00 committed by GitHub
parent 04ce318522
commit c266f0c375
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -559,6 +559,14 @@ reader_get_or_create_thread_state(BinaryReader *reader, uint64_t thread_id,
}
}
if (reader->thread_state_count >= reader->thread_count) {
PyErr_Format(PyExc_ValueError,
"Invalid thread count: sample data contains more unique threads than declared in header "
"(declared %u, found at least %zu)",
reader->thread_count, reader->thread_state_count + 1);
return NULL;
}
if (!reader->thread_states) {
reader->thread_state_capacity = 16;
reader->thread_states = PyMem_Calloc(reader->thread_state_capacity, sizeof(ReaderThreadState));