Merge "Trace Redaction - Bit index-out-of-bounds bike mask error" into main
diff --git a/src/trace_redaction/broadphase_packet_filter.cc b/src/trace_redaction/broadphase_packet_filter.cc
index 3f009f0..7b88a40 100644
--- a/src/trace_redaction/broadphase_packet_filter.cc
+++ b/src/trace_redaction/broadphase_packet_filter.cc
@@ -48,11 +48,14 @@
 
   for (auto field = decoder.ReadField(); field.valid();
        field = decoder.ReadField()) {
-    if (mask.test(field.id()) &&
-        field.id() == protos::pbzero::TracePacket::kFtraceEventsFieldNumber) {
-      OnFtraceEvents(context, field.as_bytes(), message->set_ftrace_events());
-    } else if (mask.test(field.id())) {
-      proto_util::AppendField(field, message.get());
+    // Make sure the id can be references. If it is out of bounds, it is by
+    // definition "no set".
+    if (field.id() < mask.size() && mask.test(field.id())) {
+      if (field.id() == protos::pbzero::TracePacket::kFtraceEventsFieldNumber) {
+        OnFtraceEvents(context, field.as_bytes(), message->set_ftrace_events());
+      } else {
+        proto_util::AppendField(field, message.get());
+      }
     }
   }
 
@@ -90,7 +93,9 @@
 
   for (auto field = decoder.ReadField(); field.valid();
        field = decoder.ReadField()) {
-    if (mask.test(field.id())) {
+    // Make sure the id can be references. If it is out of bounds, it is by
+    // definition "no set".
+    if (field.id() < mask.size() && mask.test(field.id())) {
       proto_util::AppendField(field, message);
     }
   }
diff --git a/src/trace_redaction/trace_redaction_framework.h b/src/trace_redaction/trace_redaction_framework.h
index 91591b6..5cd62ec 100644
--- a/src/trace_redaction/trace_redaction_framework.h
+++ b/src/trace_redaction/trace_redaction_framework.h
@@ -246,9 +246,8 @@
   // If the mask is set to 0x00, all fields would be removed. This should not
   // happen as some metadata provides context between packets.
   //
-  // Important note, 128 is used because it's the first power-of-2 after
-  // TracePacket::kMaxFieldNumber.
-  using TracePacketMask = std::bitset<128>;
+  // TracePacket has kForTestingFieldNumber which is set to 900.
+  using TracePacketMask = std::bitset<1024>;
   TracePacketMask packet_mask;
 
   // Ftrace packets contain a "one of" entry called "event". Within the scope of
@@ -288,7 +287,9 @@
   //
   //  3.  In this example, a cpu_idle event populates the one-of slot in the
   //      ftrace event
-  using FtraceEventMask = std::bitset<512>;
+  //
+  // Ftrace event has kMaliMaliPMMCURESETWAITFieldNumber which is set to 532.
+  using FtraceEventMask = std::bitset<1024>;
   FtraceEventMask ftrace_mask;
 
   //  message SuspendResumeFtraceEvent {