Skip to content

Commit

Permalink
Improve error handling for invalid NT4 msgpack types
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 29, 2023
1 parent 3b5cbba commit c7023d5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/hub/dataSources/NT4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,21 @@ export class NT4_Client {
let typeIdx = (unpackedData as unknown[])[2] as number;
let value = (unpackedData as unknown[])[3];

// Validate types
if (typeof topicID !== "number") {
console.warn("[NT4] Ignoring binary data, topic ID is not a number");
return;
}
if (typeof timestamp_us !== "number") {
console.warn("[NT4] Ignoring binary data, timestamp is not a number");
return;
}
if (typeof typeIdx !== "number") {
console.warn("[NT4] Ignoring binary data, type index is not a number");
return;
}

// Process data
if (topicID >= 0) {
if (rttOnly) {
console.warn("[NT4] Ignoring binary data, not an RTT message but received by RTT only connection");
Expand Down

0 comments on commit c7023d5

Please sign in to comment.