Skip to content
Open
Changes from all commits
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
15 changes: 14 additions & 1 deletion lib/packbeam.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down