From 4a57374bd5daee86e76c630f199dcddb65dcf242 Mon Sep 17 00:00:00 2001 From: Siebe Krijgsman Date: Mon, 16 Oct 2023 10:49:54 +0200 Subject: [PATCH 1/2] #61: Added test to trigger 0-length legacy bug --- src/test/java/TestTraceSet.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/TestTraceSet.java b/src/test/java/TestTraceSet.java index 42c5628..a865a88 100644 --- a/src/test/java/TestTraceSet.java +++ b/src/test/java/TestTraceSet.java @@ -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)); + } + } } From 740bf4ab31575492a9b2f77d6fedb981238fb18d Mon Sep 17 00:00:00 2001 From: Siebe Krijgsman Date: Mon, 16 Oct 2023 10:51:42 +0200 Subject: [PATCH 2/2] #61: Added check for data-less traces in legacy mode --- src/main/java/com/riscure/trs/TraceSet.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/riscure/trs/TraceSet.java b/src/main/java/com/riscure/trs/TraceSet.java index 7530b1c..4b7a5a9 100644 --- a/src/main/java/com/riscure/trs/TraceSet.java +++ b/src/main/java/com/riscure/trs/TraceSet.java @@ -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();