From 2ae039d3909c3e9edcb03303fb8a4242bd0051d8 Mon Sep 17 00:00:00 2001 From: Eric Engle Date: Mon, 10 Jun 2024 12:42:44 -0400 Subject: [PATCH] Update _grib2io.py When looking for the GRIB2 header string "GRIB", changed the struct.unpack format from ">i" to ">I", an unsigned integer. The integer representation of "GRIB" should never be negative. This fixes cases where other data could be in the file and a given 4 bytes represented as ">i" could be negative which raises an error. Instead, we just want to skip ahead and continue looking for "GRIB". --- src/grib2io/_grib2io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib2io/_grib2io.py b/src/grib2io/_grib2io.py index 5ef5577..85e6955 100644 --- a/src/grib2io/_grib2io.py +++ b/src/grib2io/_grib2io.py @@ -233,7 +233,7 @@ def _build_index(self): # loop when "test_offset" is 0. for test_offset in range(2048): self._filehandle.seek(pos + test_offset) - header = struct.unpack(">i", self._filehandle.read(4))[0] + header = struct.unpack(">I", self._filehandle.read(4))[0] if header.to_bytes(4, "big") == b"GRIB": pos = pos + test_offset break