From 9b16e2160f722b845f9b7e6cda1480544126004b Mon Sep 17 00:00:00 2001 From: Peter M Date: Sun, 10 Aug 2025 19:26:35 +0200 Subject: [PATCH] Fix: handle OTP28 uncompressed literals We need the try/rescue due to potential false positives on 0x78, and we need the case matching for happy path. Afaik packbeam is being unified, so this is interim quickfix. Signed-off-by: Peter M --- lib/packbeam.ex | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/packbeam.ex b/lib/packbeam.ex index 7922f43..1a2c01b 100644 --- a/lib/packbeam.ex +++ b/lib/packbeam.ex @@ -17,7 +17,20 @@ defmodule ExAtomVM.PackBEAM do defp uncompress_literals(chunks) do with {~c"LitT", litt} <- List.keyfind(chunks, ~c"LitT", 0), <<_header::binary-size(4), data::binary>> <- litt do - litu = :zlib.uncompress(data) + litu = + case data do + # RFC 1950: Valid zlib header when (CMF*256 + FLG) % 31 == 0 + <<0x78, flag, _rest::binary>> when rem(0x78 * 256 + flag, 31) == 0 -> + try do + :zlib.uncompress(data) + rescue + _error -> data + end + + # OTP 28 compatibility: data is not compressed + _ -> + data + end chunks |> List.keyreplace(~c"LitT", 0, {~c"LitU", litu})