-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Fix memory leaks and aborts in H5O EFL decode #2656
Conversation
The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. Related to GitHub HDFGroup#2605
Fixes GitHub HDFGroup#2605
@@ -111,64 +103,69 @@ H5O__efl_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED | |||
|
|||
/* Number of slots */ | |||
UINT16DECODE(p, mesg->nalloc); | |||
HDassert(mesg->nalloc > 0); | |||
if (mesg->nalloc <= 0) | |||
HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad number of allocated slots when parsing efl msg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing a malformed file should never result in an assert() call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
However, it's an unsigned value, so can't be <0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could change that to be != 0, but then that would be broken if anyone changes the type to be signed so they can have a "bad" value.
for (size_t u = 0; u < mesg->nused; u++) | ||
H5MM_xfree(mesg->slot[u].name); | ||
H5MM_xfree(mesg->slot); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mesg->slot and the names could be allocated but were not cleaned on errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest parentheses around math expressions involved in comparisons. Memorizing the precedence of operations shouldn't be the most important thing on your mind when looking at this code.
I went ahead and added parens, but I honestly don't think that remembering math > logic is too much to remember. If I get some free time, I'll add a function or macro to hide all the awkward -1 stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks :-)
void *ret_value = NULL; /* Return value */ | ||
H5O_efl_t *mesg = NULL; | ||
int version; | ||
const uint8_t *p_end = p + p_size - 1; /* pointer to last byte in p */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest possibly moving this assignment past the assert for p
since addition on a NULL pointer is undefined. That said, we don't have a normal check for p != NULL
so it won't be caught in release builds as is anyway if this ever happens. Hopefully the assert would catch it during development though.
* Convert asserts to error handling in efl decode The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. * Free memory on H5O efl decode errors * Add buffer size checks to efl msg decode * Add parentheses to math expressions Fixes GitHub HDFGroup#2605
* Convert asserts to error handling in efl decode The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. * Free memory on H5O efl decode errors * Add buffer size checks to efl msg decode * Add parentheses to math expressions Fixes GitHub HDFGroup#2605
* Convert asserts to error handling in efl decode The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. * Free memory on H5O efl decode errors * Add buffer size checks to efl msg decode * Add parentheses to math expressions Fixes GitHub #2605
* Convert asserts to error handling in efl decode The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. * Free memory on H5O efl decode errors * Add buffer size checks to efl msg decode * Add parentheses to math expressions Fixes GitHub #2605
* Convert asserts to error handling in efl decode The function that decodes external data files object header messages would call assert() when parsing malformed files, causing applications to crash when linked against the debug library. This change converts these assert() calls to HDF5 error checks, so the messages are sanity checked in both release and debug mode and debug mode no longer crashes applications. Also cleaned up some error handling usage and debug checks. * Free memory on H5O efl decode errors * Add buffer size checks to efl msg decode * Add parentheses to math expressions Fixes GitHub HDFGroup#2605
H5O__efl_decode() would call assert() and not properly clean up memory when parsing malformed external data files messages. This change corrects that behavior and fixes #2605.