Skip to content

Commit

Permalink
Merge pull request #63 from Riscure/bugfix/61-0-length-data
Browse files Browse the repository at this point in the history
Bugfix/61 0 length data
  • Loading branch information
TomHogervorst authored Oct 17, 2023
2 parents 58a8eab + 740bf4a commit 8cc47ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/riscure/trs/TraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public Trace get(int index) throws IOException {
//legacy mode
byte[] data = readData();
traceParameterMap = new TraceParameterMap();
traceParameterMap.put("LEGACY_DATA", data);
if (data.length > 0) {
traceParameterMap.put("LEGACY_DATA", data);
}
}

float[] samples = readSamples();
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/TestTraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,20 @@ void testReadTwoBeyondTracesetLimit() throws IOException, TRSFormatException {
.getMessage().startsWith("Requested trace index"));
}
}

/**
* Test to reproduce Github issue #61: Reading a legacy trace with a 0-length data field
*/
@Test
void test61ReadLegacyTraceWithoutData() throws IOException, TRSFormatException {
Path filePath = tempDir.resolve("test_issue_61.trs");
TRSMetaData metaData = new TRSMetaData();
metaData.put(TRSTag.TRS_VERSION, 1);
try (TraceSet ts = TraceSet.create(filePath.toString(), metaData)) {
ts.add(new Trace(new float[]{}));
}
try (TraceSet ts = TraceSet.open(filePath.toString())) {
assertDoesNotThrow(() -> ts.get(0));
}
}
}

0 comments on commit 8cc47ea

Please sign in to comment.