Fix complex packing decode crash on trailing padding bits

consume_bits would crash with a MatchError when the remaining
bitstring had fewer bits than the group width. Added a guard
clause to stop consuming when insufficient bits remain, matching
how wgrib2 handles trailing padding in packed data sections.
This commit is contained in:
Graham McIntire 2026-03-30 07:52:06 -05:00
parent 5a9359191f
commit 3749360a28
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -191,7 +191,7 @@ defmodule Microwaveprop.Weather.Grib2.ComplexPacking do
end
end
defp consume_bits(<<>>, _width, _gref, acc), do: acc
defp consume_bits(bits, width, _gref, acc) when bit_size(bits) < width, do: acc
defp consume_bits(bits, width, gref, acc) do
<<val::size(width)-unsigned-big, rest::bitstring>> = bits