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

Various fixes #1640

Closed
wants to merge 10 commits into from
Closed

Various fixes #1640

wants to merge 10 commits into from

Conversation

mathstuf
Copy link
Contributor


Various fixes from VTK's bundled HDF5 that we've applied that seems relevant for upstream.

@mathstuf
Copy link
Contributor Author

I can split this into multiple PRs if that is preferred as well.

@@ -190,9 +190,6 @@
/* Define to 1 if you have the `curl' library (-lcurl). */
#cmakedefine H5_HAVE_LIBCURL @H5_HAVE_LIBCURL@

/* Define to 1 if you have the `dl' library (-ldl). */
Copy link
Contributor

Choose a reason for hiding this comment

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

We still maintain two build systems: CMake and autotools/autoconf.
This file needs to remain in sync with the file generated by autoconf until such time that we no longer support autoconf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing cares if this define is present or not, so it isn't doing anything in the header.

Copy link
Member

Choose a reason for hiding this comment

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

We keep this file in sync with the one produced by Autoconf so it's easier to eyeball them to make sure we aren't missing something in the other build system.

Copy link
Member

Choose a reason for hiding this comment

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

A lot of these header files are useless, though, and have already been removed from configure.ac.

if (MINGW OR NOT WINDOWS)
CHECK_LIBRARY_EXISTS_CONCAT ("m" ceil ${HDF_PREFIX}_HAVE_LIBM)
CHECK_LIBRARY_EXISTS_CONCAT ("dl" dlopen ${HDF_PREFIX}_HAVE_LIBDL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does mingw not need these? Mingw generates windows objects on linux, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but there is no libdl in MinGW as it uses LoadLibrary. Maybe you're thinking of Cygwin?

HDstrncat(full_path, H5_DIR_SEPS, path_len - (cwdlen + 1));
HDstrncat(full_path, new_name, path_len - (cwdlen + 1) - HDstrlen(H5_DIR_SEPS));
HDstrcat(full_path, H5_DIR_SEPS);
HDstrcat(full_path, new_name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change seems like it will possibly be reintroducing a vulnerability by not calculating how much space is left in full_path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The correct length is allocated right above this.

@@ -1043,76 +1043,40 @@ target_compile_options(H5detect
)
set (lib_prog_deps ${lib_prog_deps} H5detect)

# check if a pregenerated H5Tinit.c file is present
if (NOT EXISTS "${HDF5_GENERATED_SOURCE_DIR}/H5Tinit.c")
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is if we are cross-compiling with a pre-generated file - because the host system cannot generate a file for the target system. How is it handled in your changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hrm. This causes problems because rerunning the configure after the build happens causes it to detect the "pre-generated" file and confuses reconfigures. I think another approach for cross-compilations where the source directory gets the to-be-used file is used instead of overloading the existence of the output like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is a cross-compiling emulator available (e.g., Wine when doing MinGW on Linux), it will be able to run the binary. So it's not just "cross compiling, therefore impossible".

${HDF5_SOURCE_DIR}/bin/batch/${HDF5_BATCH_H5DETECT_SCRIPT}.in.cmake
${HDF5_BINARY_DIR}/${HDF5_BATCH_H5DETECT_SCRIPT} ESCAPE_QUOTES @ONLY
)
add_custom_command (
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this form of add_custom_command work correctly with the ninja system?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's what I tested it with. I'm not really sure why the stamp gymnastics were done previously as they just overcomplicated it instead of making anything actually work (AFAICT).

@@ -310,6 +310,7 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes should be made in H5LTanalyze.l. H5LTanalyze.c is generated by lex from H5LTanalyze.l.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commit message mentions that flex generates the bits that it doesn't include for. I can include it there, but flex should really be adding the include for its generated code. I'll add a comment there to that effect.

Copy link
Member

Choose a reason for hiding this comment

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

This is fixed in develop

Copy link
Member

@derobins derobins left a comment

Choose a reason for hiding this comment

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

The proposed changes need justification/discussion

HDstrncat(full_path, H5_DIR_SEPS, path_len - (cwdlen + 1));
HDstrncat(full_path, new_name, path_len - (cwdlen + 1) - HDstrlen(H5_DIR_SEPS));
HDstrcat(full_path, H5_DIR_SEPS);
HDstrcat(full_path, new_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about a defensive rewrite using snprintf?

            int rc = snprintf(full_path, path_len, "%s%s%s", cwdpath,
                H5_CHECK_DELIMITER(cwdpath[cwdlen - 1]) ? "" : H5_DIR_SEPS,
                new_name);
            if (rc < 0 || (size_t)rc >= path_len) {
                HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL,
                    "buffer would overflow")
            }

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that would certainly be a bit less prone to error, though maybe a little bit less clean. I'd be for doing that though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm all for using safer C string manip functions :) .

However, if there's an overflow, that is a logic error in this function as path_len is calcuated right above.

These calls did `strop(dst, src, strlen(src))` in some form or another.
The size to these operations is the size of the *destination* buffer;
the source size is implicit with `NUL` termination.
Other locations check if it is defined and in cases where it is not
available, it is undefined, not 0.
These were checked for at configure time, but nothing in the code cared
about their results. Remove the checks.
This is actually a bug in flex, not the grammar file.
@mathstuf
Copy link
Contributor Author

The proposed changes need justification/discussion

Please see the commit messages. Are there any that are deficient?

In release builds, `assert`-like macros disappear and cause some
variables to be detected as unused. Add a "fake" usage to let the
compiler know that things are as intended.
@mathstuf
Copy link
Contributor Author

Oh, there's stuff to perserve here.

@mathstuf mathstuf reopened this Jul 22, 2022
@mathstuf mathstuf marked this pull request as draft July 22, 2022 19:29
@derobins
Copy link
Member

Yeah, I've been meaning to go over this again to see what's up with all the changes.

@@ -656,6 +656,7 @@ H5T__ref_mem_write(H5VL_object_t *src_file, const void *src_buf, size_t src_size
HDassert(dst_buf);
HDassert(dst_size == H5T_REF_MEM_SIZE);
HDcompile_assert(sizeof(*dst_ref) == sizeof(tmp_ref));
(void)dst_size;
Copy link
Member

Choose a reason for hiding this comment

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

This is fixed in develop

@@ -590,6 +590,8 @@ H5O__shared_copy_file(H5F_t H5_ATTR_NDEBUG_UNUSED *file_src, H5F_t *file_dst,
HDassert(shared_dst);
HDassert(recompute_size);
HDassert(cpy_info);
(void)file_src;
(void)cpy_info;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -3045,6 +3045,8 @@ H5O__free(H5O_t *oh, hbool_t force)
oh->ndecode_dirtied--;
else if (!force)
HDassert(oh->mesg[u].dirty == 0);
#else
(void)force;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -750,6 +752,7 @@ H5O__cache_chk_deserialize(const void *image, size_t len, void *_udata, hbool_t
HDassert(udata);
HDassert(udata->oh);
HDassert(dirty);
(void)len;
Copy link
Member

Choose a reason for hiding this comment

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

len is used below

@@ -302,6 +303,7 @@ H5O__cache_deserialize(const void *image, size_t len, void *_udata, hbool_t *dir
HDassert(udata->common.f);
HDassert(udata->common.cont_msg_info);
HDassert(dirty);
(void)len;
Copy link
Member

Choose a reason for hiding this comment

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

len is used below

@@ -197,6 +197,7 @@ H5O__cache_get_final_load_size(const void *image, size_t H5_ATTR_NDEBUG_UNUSED i
HDassert(udata);
HDassert(actual_len);
HDassert(*actual_len == image_len);
(void)image_len;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

} /* end if */
} /* end if */
#else
(void)f;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -1085,6 +1085,7 @@ H5FD__sec2_ctl(H5FD_t *_file, uint64_t op_code, uint64_t flags, const void H5_AT

/* Sanity checks */
HDassert(file);
(void)file;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

uint64_t * elmt = (uint64_t *)_elmt; /* Convenience pointer to native elements */
const uint8_t *raw = (const uint8_t *)_raw; /* Convenience pointer to raw elements */
#else
(void)_ctx;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -614,6 +614,7 @@ H5D__contig_may_use_select_io(const H5D_io_info_t *io_info, H5D_io_op_type_t op_
HDassert(io_info);
HDassert(dataset);
HDassert(op_type == H5D_IO_OP_READ || op_type == H5D_IO_OP_WRITE);
(void)dataset;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -8114,6 +8114,7 @@ H5D__chunk_iter(const H5D_t *dset, H5D_chunk_iter_op_t op, void *op_data)
HDassert(layout);
HDassert(rdcc);
HDassert(H5D_CHUNKED == layout->type);
(void)layout;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@@ -2148,6 +2148,7 @@ H5A__attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_s
HDassert(file_dst);
HDassert(cpy_info);
HDassert(!cpy_info->copy_without_attr);
(void)cpy_info;
Copy link
Member

Choose a reason for hiding this comment

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

Fixed in develop

@derobins derobins self-assigned this Feb 17, 2023
@derobins derobins added WIP Work in progress (please also convert PRs to draft PRs) Type - Improvement Improvements that don't add a new feature or functionality labels Mar 3, 2023
@derobins derobins added Merge - To 1.12 Merge - To 1.14 This needs to be merged to HDF5 1.14 Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Component - C Library Core C library issues (usually in the src directory) Component - High-Level Library Code in the hl directory Component - Build CMake, Autotools labels May 25, 2023
@derobins
Copy link
Member

derobins commented Jun 7, 2023

I think we've pulled everything we can out of this. The one thing that is left is the cross-compiling bits, but I'm going to leave that to a future discussion.

@derobins derobins closed this Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Build CMake, Autotools Component - C Library Core C library issues (usually in the src directory) Component - High-Level Library Code in the hl directory Merge - To 1.14 This needs to be merged to HDF5 1.14 Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Type - Improvement Improvements that don't add a new feature or functionality WIP Work in progress (please also convert PRs to draft PRs)
Projects
Status: Merges Complete
Development

Successfully merging this pull request may close these issues.

None yet

7 participants