From e74b800445cbe502511905105e769a1ca33b8381 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 30 Dec 2021 18:52:10 +0100 Subject: jgvariant-ostree: DeltaPartPayload: Detect and handle compression byte. Change-Id: I6d5aa4deb7c94bafae1fb5f92c68cdb4809ceca0 --- .../eu/mulk/jgvariant/ostree/DeltaPartPayload.java | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'jgvariant-ostree/src/main') diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java index 7f7dd23..99e093d 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaPartPayload.java @@ -1,6 +1,7 @@ package eu.mulk.jgvariant.ostree; import eu.mulk.jgvariant.core.Decoder; +import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.List; @@ -27,11 +28,23 @@ public record DeltaPartPayload( private static final Decoder DECODER = Decoder.ofStructure( - DeltaPartPayload.class, - Decoder.ofArray(FileMode.decoder()), - Decoder.ofArray(Decoder.ofArray(Xattr.decoder())), - ByteString.decoder(), - ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList)); + DeltaPartPayload.class, + Decoder.ofArray(FileMode.decoder()), + Decoder.ofArray(Decoder.ofArray(Xattr.decoder())), + ByteString.decoder(), + ByteString.decoder().map(DeltaPartPayload::parseDeltaOperationList)) + .contramap(DeltaPartPayload::preparse); + + private static ByteBuffer preparse(ByteBuffer byteBuffer) { + byte compressionByte = byteBuffer.get(0); + return switch (compressionByte) { + case 0 -> byteBuffer.slice(1, byteBuffer.limit()); + case (byte) 'x' -> throw new UnsupportedOperationException( + "LZMA compression of static deltas is unsupported"); + default -> throw new IllegalArgumentException( + "unrecognized compression byte '%d'".formatted(compressionByte)); + }; + } private static List parseDeltaOperationList(ByteString byteString) { return byteString.stream().map(DeltaOperation::valueOf).toList(); -- cgit v1.2.3