Skip to content

hfiledd.c: fix integer overflow and memleak on corrupted file#874

Open
rouault wants to merge 1 commit into
HDFGroup:masterfrom
rouault:ossfuzz_fixes
Open

hfiledd.c: fix integer overflow and memleak on corrupted file#874
rouault wants to merge 1 commit into
HDFGroup:masterfrom
rouault:ossfuzz_fixes

Conversation

@rouault
Copy link
Copy Markdown

@rouault rouault commented May 11, 2026

Found by running locally oss-fuzz on GDAL with HDF4 support enabled. This is likely just the tip of the iceberg. I fixed 2 issues (an integer overflow and a memory leak), and then retried again the fuzzing, and it immediately found another memory leak...

I can provide the reproducer if needed

Copy link
Copy Markdown
Collaborator

@schwehr schwehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change as it is currently written is acceptable for me. My comments are mostly just nits that probably can't go in as they deviate from the established style in hdf4.

@bmribler Can you respond on the style issues here for @rouault ?

I agree with Even that there are likely a lot more issues lurking in this code. A quick AI analysis of the code in just this file found 8 likely places for integer overflows. :(

Comment thread hdf/src/hfiledd.c
#include "hfile_priv.h"

/* Private routines */
static void HTPmemory_cleanup(filerec_t *file_rec);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this file has traditionally had prototypes and define the code below, but can we switch to just having the function here?

Comment thread hdf/src/hfiledd.c
{
ddblock_t *bl, *next; /* current ddblock and next ddblock pointers.
for freeing ddblock linked list */
for (bl = file_rec->ddhead; bl != NULL; bl = next) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we use C99 and just make it:

for (ddblock_t *bl = file_rec->ddhead, *next; bl != NULL; bl = next) {

Comment thread hdf/src/hfiledd.c
static void
HTPmemory_cleanup(filerec_t *file_rec)
{
ddblock_t *bl, *next; /* current ddblock and next ddblock pointers.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Free the ddblock linked list.

Comment thread hdf/src/hfiledd.c
}
file_rec->ddhead = (ddblock_t *)NULL;

/* Chuck the tag info tree too */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Deallocate the tag info tree.

@bmribler
Copy link
Copy Markdown
Collaborator

The change as it is currently written is acceptable for me. My comments are mostly just nits that probably can't go in as they deviate from the established style in hdf4.

@bmribler Can you respond on the style issues here for @rouault ?

I agree with Even that there are likely a lot more issues lurking in this code. A quick AI analysis of the code in just this file found 8 likely places for integer overflows. :(

I'm working my way down the list... Thank you, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants