Skip to content

Commit 550d22f

Browse files
committed
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 <[email protected]>
1 parent 27ddd7d commit 550d22f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/packbeam.ex

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ defmodule ExAtomVM.PackBEAM do
1717
defp uncompress_literals(chunks) do
1818
with {~c"LitT", litt} <- List.keyfind(chunks, ~c"LitT", 0),
1919
<<_header::binary-size(4), data::binary>> <- litt do
20-
litu = :zlib.uncompress(data)
20+
litu =
21+
case data do
22+
# RFC 1950: Valid zlib header when (CMF*256 + FLG) % 31 == 0
23+
<<0x78, flag, _rest::binary>> when rem(0x78 * 256 + flag, 31) == 0 ->
24+
try do
25+
:zlib.uncompress(data)
26+
rescue
27+
_error -> data
28+
end
29+
30+
# OTP 28 compatibility: data is not compressed
31+
_ ->
32+
data
33+
end
2134

2235
chunks
2336
|> List.keyreplace(~c"LitT", 0, {~c"LitU", litu})

0 commit comments

Comments
 (0)