Skip to content

Commit

Permalink
Ignore usages past 64 bytes in the report
Browse files Browse the repository at this point in the history
This commit makes it so that the report descriptor parser doesn't
store information about usages located beyond 64 bytes in the report.

We're not currently handling reports longer than 64 bytes anyway and
this protects us from running out of memory on some broken report
descriptors with thousands of declared usages.
  • Loading branch information
jfedor2 committed Jan 2, 2024
1 parent a4d4602 commit 4a5b6d6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions firmware/src/descriptor_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ void mark_usage(
uint32_t index = 0,
uint32_t count = 0,
uint32_t usage_maximum = 0) {
if (bitpos >= (8 * ((report_id == 0) ? 64 : 63))) {
// We don't currently handle reports longer than 64 bytes so let's save some memory.
// It's probably a broken descriptor anyway.
return;
}

(*usage_map)[report_id].try_emplace(usage,
(usage_def_t){
.report_id = report_id,
Expand Down

0 comments on commit 4a5b6d6

Please sign in to comment.