-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update g2_gribend / g2c_check_msg for rare condition #438
Comments
Maybe we should just cut this code:
|
I think the above is needed. I am looking at |
If you have a solution, that would be great. I didn't see an easy way to do that... |
This commit fixes a rare condition in which the last 4 bytes of a packed section 7 could equal "7777" which is the GRIB end of message terminating string and triggers an erroneous end of message status. The added logic checks for "7777" at the end of cgrib under the condition that we have a valid GRIB message through seciton 7. This commit references NOAA-EMC#438
Lets table this for v1.10 |
The next version (v2.0.0) will be released soon. Should this be bumped to the next release? |
I have talked about this rare condition on a few occasions with different groups of people. Someone suggested that if the last 4 bytes of the packed data are [55, 55, 55, 55] (i.e. "7777"), then just make the last byte either 54 or 56. In theory, this byte would only impact a corner of the grid. Thoughts? |
Don't we know the size of the section anyway? In other words do we need to scan for 7777? |
Continuing to look at this... /* Loop through all current sections of the GRIB message to find
* the last section number. */
len = 16; /* Length of Section 0. */
for (;;)
{
/* Get number and length of next section. */
iofst = len * 8;
gbit(cgrib, &ilen, iofst, 32);
iofst = iofst + 32;
gbit(cgrib, &isecnum, iofst, 8);
len = len + ilen;
/* Exit loop if last section reached. */
if (len == lencurr)
break;
/* If byte count for each section doesn't match current
* total length, then there is a problem. */
if (len > lencurr)
{
printf("g2_gribend: Section byte counts don''t add to total.\n");
printf("g2_gribend: Sum of section byte counts = %d\n", (int)len);
printf("g2_gribend: Total byte count in Section 0 = %d\n", (int)lencurr);
return G2_BAD_SEC_COUNTS;
}
} If you look at And perhaps it should conditionally check for the end section? The modified workflow in
|
I came across a rare condition when addressing a grib2io issue. In short, the user was trying to pack data using simple packing, no decimal or binary scaling, and nbits=0. This results in the packing the data to the nearest integer. Just so happens that the last 4 values of the grid rounded to a value of 55, which resolves to "7" in the ASCII table. In this scenario, g2c thinks the GRIB2 message is complete and gives a non-zero return status.
Therefore, I think
g2_gribend
and/org2c_check_msg
need to check for this rare condition.Thinking about this a bit, perhaps
g2c_check_msg
should check the length of section 7 and if the last 4 bytes are "7777" (assuming section length is correct), then to not trigger the error.The text was updated successfully, but these errors were encountered: