Skip to content

Commit

Permalink
Skip invalid WPILOG control records (#233)
Browse files Browse the repository at this point in the history
* Skip invalid WPILOG control records

* Stop decoding on invalid WPILOG record
  • Loading branch information
jwbonner authored Oct 16, 2024
1 parent 3a40d30 commit 06b4c90
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 49 deletions.
7 changes: 7 additions & 0 deletions src/hub/dataSources/wpilog/indexer/wpilogIndexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ void* run(void* buffer, int bufferSize) {
uint8_t dataSizeLength = ((lengthBitfield >> 2) & 0x3) + 1;
uint8_t timestampLength = ((lengthBitfield >> 4) & 0x7) + 1;
uint8_t headerLength = 1 + entryLength + dataSizeLength + timestampLength;
if (bufferSize < offset + headerLength) {
break;
}

uint32_t entry = readVarInt(buffer, offset + 1, entryLength);
uint32_t dataSize =
readVarInt(buffer, offset + 1 + entryLength, dataSizeLength);
int64_t timestamp = readVarInt(
buffer, offset + 1 + entryLength + dataSizeLength, timestampLength);
if (bufferSize < offset + headerLength + dataSize || entry < 0 ||
dataSize < 0) {
break;
}

// Update timestamp range
if (entry != CONTROL_ENTRY) {
Expand Down
100 changes: 51 additions & 49 deletions src/hub/dataSources/wpilog/wpilogWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,57 @@ async function start(data: Uint8Array) {
},
(entry, position) => {
if (entry === CONTROL_ENTRY) {
let record = decoder!.getRecordAtPosition(position)[0]!;
if (record.isStart()) {
const startData = record.getStartData();
entryIds[startData.entry] = startData.name;
entryTypes[startData.name] = startData.type;
dataRecordPositions[startData.name] = [];
switch (startData.type) {
case "boolean":
log.createBlankField(startData.name, LoggableType.Boolean);
break;
case "int":
case "int64":
case "float":
case "double":
log.createBlankField(startData.name, LoggableType.Number);
break;
case "string":
case "json":
log.createBlankField(startData.name, LoggableType.String);
break;
case "boolean[]":
log.createBlankField(startData.name, LoggableType.BooleanArray);
break;
case "int[]":
case "int64[]":
case "float[]":
case "double[]":
log.createBlankField(startData.name, LoggableType.NumberArray);
break;
case "string[]":
log.createBlankField(startData.name, LoggableType.StringArray);
break;
default: // Default to raw
log.createBlankField(startData.name, LoggableType.Raw);
if (startData.type.startsWith(STRUCT_PREFIX)) {
let schemaType = startData.type.split(STRUCT_PREFIX)[1];
log.setStructuredType(startData.name, schemaType);
} else if (startData.type.startsWith(PROTO_PREFIX)) {
let schemaType = startData.type.split(PROTO_PREFIX)[1];
log.setStructuredType(startData.name, schemaType);
}
break;
}
log.setWpilibType(startData.name, startData.type);
log.setMetadataString(startData.name, startData.metadata);
} else if (record.isSetMetadata()) {
let setMetadataData = record.getSetMetadataData();
if (setMetadataData.entry in entryIds) {
log.setMetadataString(entryIds[setMetadataData.entry], setMetadataData.metadata);
let record = decoder?.getRecordAtPosition(position)[0];
if (record !== null && record !== undefined) {
if (record.isStart()) {
const startData = record.getStartData();
entryIds[startData.entry] = startData.name;
entryTypes[startData.name] = startData.type;
dataRecordPositions[startData.name] = [];
switch (startData.type) {
case "boolean":
log.createBlankField(startData.name, LoggableType.Boolean);
break;
case "int":
case "int64":
case "float":
case "double":
log.createBlankField(startData.name, LoggableType.Number);
break;
case "string":
case "json":
log.createBlankField(startData.name, LoggableType.String);
break;
case "boolean[]":
log.createBlankField(startData.name, LoggableType.BooleanArray);
break;
case "int[]":
case "int64[]":
case "float[]":
case "double[]":
log.createBlankField(startData.name, LoggableType.NumberArray);
break;
case "string[]":
log.createBlankField(startData.name, LoggableType.StringArray);
break;
default: // Default to raw
log.createBlankField(startData.name, LoggableType.Raw);
if (startData.type.startsWith(STRUCT_PREFIX)) {
let schemaType = startData.type.split(STRUCT_PREFIX)[1];
log.setStructuredType(startData.name, schemaType);
} else if (startData.type.startsWith(PROTO_PREFIX)) {
let schemaType = startData.type.split(PROTO_PREFIX)[1];
log.setStructuredType(startData.name, schemaType);
}
break;
}
log.setWpilibType(startData.name, startData.type);
log.setMetadataString(startData.name, startData.metadata);
} else if (record.isSetMetadata()) {
let setMetadataData = record.getSetMetadataData();
if (setMetadataData.entry in entryIds) {
log.setMetadataString(entryIds[setMetadataData.entry], setMetadataData.metadata);
}
}
}
} else if (entry in entryIds) {
Expand Down

0 comments on commit 06b4c90

Please sign in to comment.