Skip to content
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

Add H5Tdecode2, rename and deprecate H5Tdecode #5213

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

mattjala
Copy link
Contributor

@mattjala mattjala commented Jan 7, 2025

When provided malformed or too-small buffers, H5Tdecode() could crash due to walking off the end of the buffer. The new buffer size parameter allows this to be reliably avoided.

Resolves #4661

@mattjala mattjala added Merge - Develop Only This cannot be merged to previous versions of HDF5 (file format or breaking API changes) Priority - 2. Medium ⏹ It would be nice to have this in the next release Component - C Library Core C library issues (usually in the src directory) Type - New Feature Add a new API call, functionality, or tool Branch - 2.0 PRs to the HDF5 2.x maintenance branch labels Jan 7, 2025
@mattjala mattjala added this to the 2.0.0 milestone Jan 7, 2025
release_docs/RELEASE.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@qkoziol qkoziol left a comment

Choose a reason for hiding this comment

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

Looks very good, just needs a test for H5Tdecode1

test/dtypes.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a new test that exercises the deprecated H5Tdecode1 routine.

@mattjala mattjala requested a review from qkoziol January 8, 2025 16:27
// Call C function to decode the binary object description
hid_t encoded_dtype_id = H5Tdecode(encoded_buf);
hid_t encoded_dtype_id = H5Tdecode2(encoded_buf, tmp_buf_size);

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for addressing the issue, but I'm sorry, I made a mistake in the original comment. If encoded_buf is not NULL then buf_size will already be the size of the encoded buffer. You can safely use buf_size in H5Tdecode2 as you originally did. I'm sorry again!

Copy link
Contributor

@bmribler bmribler Jan 8, 2025

Choose a reason for hiding this comment

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

Without having to call H5Tencode to get the size, that is. Checking buf_size is a good idea though. However, if you want to put a fix in DataType::close() to set encoded_buf to NULL then checking for NULL encoded_buf alone will be good enough. Question me if you see anything I said questionable. :D

@@ -13883,7 +13886,7 @@ public static long H5Tdecode(byte[] buf) throws HDF5LibraryException, NullPointe
return id;
}

private synchronized static native long _H5Tdecode(byte[] buf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

At first I was going to mention that there should be the corresponding JNI changes, but it seems there is no _H5Tdecode implementation currently. @byrnHDF We should either implement that or remove this function from being available.

src/H5T.c Outdated
@@ -3812,6 +3807,9 @@ H5T_decode(size_t buf_size, const unsigned char *buf)
if (NULL == (f = H5F_fake_alloc((uint8_t)0)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "can't allocate fake file struct");

if (buf_size < 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big fan of an explicit comparison against the value 2 here. Using 2 occurrences of the H5_IS_BUFFER_OVERFLOW with a size of 1, for example, might be more verbose, but IMO is a lot clearer about what's going on.

src/H5T.c Outdated Show resolved Hide resolved
src/H5Tpublic.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Branch - 2.0 PRs to the HDF5 2.x maintenance branch Component - C Library Core C library issues (usually in the src directory) Merge - Develop Only This cannot be merged to previous versions of HDF5 (file format or breaking API changes) Priority - 2. Medium ⏹ It would be nice to have this in the next release Type - New Feature Add a new API call, functionality, or tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

H5Tdecode should require buffer size parameter
4 participants