Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip invalid WPILOG control records #233

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
102 changes: 52 additions & 50 deletions src/hub/dataSources/wpilog/wpilogWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,58 +47,60 @@ 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 {
} else if (entry in entryIds) {
let key = entryIds[entry];
dataRecordPositions[key].push(position);
}
Expand Down