From 3749360a28641eae73377ebaff3dafd72e01eb5f Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 30 Mar 2026 07:52:06 -0500 Subject: [PATCH] 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. --- lib/microwaveprop/weather/grib2/complex_packing.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/microwaveprop/weather/grib2/complex_packing.ex b/lib/microwaveprop/weather/grib2/complex_packing.ex index 8912f78c..abc5d909 100644 --- a/lib/microwaveprop/weather/grib2/complex_packing.ex +++ b/lib/microwaveprop/weather/grib2/complex_packing.ex @@ -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 <> = bits