Fix parsing of GRIB2 files without Section 2 (Local Use Section)#2
Open
SebastienN15 wants to merge 1 commit intoUdSAES:masterfrom
Open
Fix parsing of GRIB2 files without Section 2 (Local Use Section)#2SebastienN15 wants to merge 1 commit intoUdSAES:masterfrom
SebastienN15 wants to merge 1 commit intoUdSAES:masterfrom
Conversation
Section 2 (Local Use Section) is optional in GRIB2 files according to the WMO GRIB2 specification, and it is recommended not to use it for international data exchange. However, the library was always attempting to parse Section 2, causing incorrect section offsets when it was absent. This resulted in the parser reading subsequent sections with wrong offsets, leading to errors like "PRODUCT_DEFINITION_TEMPLATE_NOT_SUPPORTED" with bogus template numbers. Changes: - Modified parseAllSections() to check if Section 2 is present by reading the section number byte (offset +4 after the section length) - Only parse Section 2 if the section number is 2 - Properly adjust offsets for Section 3 and subsequent sections whether or not Section 2 is present This fix maintains backward compatibility with GRIB2 files that include Section 2 (like DWD files) while also supporting files that omit it (like Météo-France Arome files and other standard GRIB2 files). All existing tests pass with this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Author
|
@florianwagner this would unblock reading grib files from Météo France, let me know if that's good for you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug where the library fails to parse valid GRIB2 files that omit Section 2 (Local Use Section), which is optional according to the WMO GRIB2 specification.
Problem
The library was always attempting to parse Section 2, even though it's optional in GRIB2 files. According to the GRIB2 specification, Section 2 (Local Use Section) is optional and recommended not to be used for international data exchange.
When parsing GRIB2 files that omit Section 2 (such as Météo-France Arome files), the parser would read subsequent sections with incorrect offsets, leading to errors like:
The bogus template number (31747 in this case) is actually random bytes from a later section being misinterpreted as the Product Definition Template number.
Solution
Modified the
parseAllSections()function to:Compatibility
Testing
Tested with:
Files Changed
index.js: ModifiedparseAllSections()function (lines 302-314)References
According to WMO GRIB2 specification: