Skip to content

Commit 150341a

Browse files
gmarin13s-kanev
authored andcommitted
Check that the read attr struct size is at most equal to the declared size of the event payload.
Any remaining bytes are event IDs. But if the declared payload size is smaller, subtracting these unsigned values when computing the number of IDs yields a very large number, which subsequently leads to a memory allocation failure. PiperOrigin-RevId: 688313672
1 parent 6d2b177 commit 150341a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/quipper/perf_reader.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,12 @@ bool PerfReader::ReadAttrEventBlock(DataReader* data, size_t size) {
23602360

23612361
// attr.attr.size has been upgraded to the current size of perf_event_attr.
23622362
const size_t actual_attr_size = data->Tell() - initial_offset;
2363+
if (size < actual_attr_size) {
2364+
LOG(ERROR) << "Declared payload size " << size << " of "
2365+
<< "PERF_RECORD_HEADER_ATTR event is less than the number of "
2366+
<< "bytes read for the attr_event struct " << actual_attr_size;
2367+
return false;
2368+
}
23632369

23642370
const size_t num_ids =
23652371
(size - actual_attr_size) / sizeof(decltype(attr.ids)::value_type);

0 commit comments

Comments
 (0)