Skip to content

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

Open
rouault wants to merge 2 commits into
HDFGroup:masterfrom
rouault:ossfuzz_fixes
Open

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

Conversation

@rouault

@rouault rouault commented May 11, 2026

Copy link
Copy Markdown

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

@schwehr schwehr left a comment

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.

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?

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.

In my opinion, it is beneficial to keep the local prototypes at the top for HDF4. It's easier to get a quick overview of all the local functions in a file. That is convenient when reusing is being considered.

Comment thread hdf/src/hfiledd.c Outdated
Comment thread hdf/src/hfiledd.c Outdated
Comment thread hdf/src/hfiledd.c Outdated
@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!

@bmribler
bmribler self-requested a review June 11, 2026 19:46
@bmribler

Copy link
Copy Markdown
Collaborator

@rouault I think offset should also be verified to be >= 0, like length, in case of corrupted files.

Comment thread hdf/src/hfiledd.c Outdated
@bmribler

Copy link
Copy Markdown
Collaborator

Hi @rouault, we're going to have code freeze this Friday, Aug 21. Would you be able to finish this PR for review so it can be merged by then? FYI, this release is planned to be the last release of HDF4. Thanks so much!

@rouault

rouault commented Aug 17, 2026

Copy link
Copy Markdown
Author

Would you be able to finish this PR for review

done

@bmribler

Copy link
Copy Markdown
Collaborator

Would you be able to finish this PR for review

done

Thank you!

@bmribler
bmribler requested review from bmribler and schwehr August 21, 2026 02:21
@bmribler

Copy link
Copy Markdown
Collaborator

Hi @rouault, I forgot to ask but, yes, please provide the reproducer when you get a chance. I go ahead and approve it now to speed things up.

@rouault

rouault commented Aug 21, 2026

Copy link
Copy Markdown
Author

please provide the reproducer when you get a chance

unfortunately I seem to have cleaned up the ossfuzz output directory where it had been generated

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