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

Fix invalid checksum error #1380

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Add unit test to test that shuffle gets applied to data that is not a…
… multiple of the element size
Tara Drwenski committed Aug 22, 2024
commit b3202793db8f0fd08db40ea91d70426027d2fd82
22 changes: 22 additions & 0 deletions cdm/core/src/test/java/ucar/nc2/filter/TestFilters.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import ucar.unidata.io.RandomAccessFile;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -59,6 +60,27 @@ public void testShuffle() throws IOException {
testEncodeDecode(filter, "shuffle");
}

@Test
public void shouldShuffleDoublesAndLeaveIntAtEnd() throws IOException {
ByteBuffer bb = ByteBuffer.allocate(2 * 8 + 4);
bb.putDouble(-1.0);
bb.putDouble(1.0);
// to represent a checksum at the end of a chunk of doubles
bb.putInt(12345);
byte[] bytes = bb.array();

Map<String, Object> props = new HashMap<>();
props.put("id", "shuffle");
props.put("elementsize", 8);
Filter filter = new Shuffle(props);

byte[] expected = new byte[] {-65, 63, -16, -16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 57};
byte[] encoded = filter.encode(bytes);
assertThat(encoded).isEqualTo(expected);
byte[] decoded = filter.decode(encoded);
assertThat(decoded).isEqualTo(bytes);
}

@Test
public void testChecksum32() throws IOException {
// test Adler32