Skip to content

Backport to 6.2#1166

Open
eivindjahren wants to merge 5 commits into
version-6.2from
backport_to_6.2
Open

Backport to 6.2#1166
eivindjahren wants to merge 5 commits into
version-6.2from
backport_to_6.2

Conversation

@eivindjahren
Copy link
Copy Markdown
Collaborator

@eivindjahren eivindjahren commented May 13, 2026

Backports fixes that are on main branch to version 6.2 . The only difference is that throws are now util_abort. This is to avoid changes to the error handling semantics.

@eivindjahren eivindjahren changed the base branch from main to version-6.2 May 13, 2026 13:53
@eivindjahren eivindjahren force-pushed the backport_to_6.2 branch 2 times, most recently from 4ea055b to b767436 Compare May 13, 2026 13:58
Comment thread lib/resdata/rd_grid.cpp Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR appears to backport robustness fixes (likely from a newer branch) into the 6.2 line, focused on safer handling of GRDECL inputs and zero-length keywords, plus some CI build configuration adjustments.

Changes:

  • Add Python-side handling for zero-length ResdataKW in get_min_max() and numpy_view().
  • Harden GRDECL/grid parsing in C++ (buffer sizing, numeric parsing widths, and keyword-size/dimension validation with util_abort).
  • Update cibuildwheel configuration to skip *-win32 builds.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/rd_tests/test_rd_kw.py Adds a regression test asserting empty GRDECL bodies produce a zero-length keyword.
python/resdata/resfile/rd_kw.py Adds safe behavior for empty keywords in get_min_max() and numpy_view().
pyproject.toml Updates cibuildwheel skip matrix to exclude win32.
lib/resdata/rd_kw.cpp Adds an abort guard for typed max/min wrappers on zero-length keywords.
lib/resdata/rd_kw_grdecl.cpp Adjusts GRDECL token buffer sizing and float/double scan widths.
lib/resdata/rd_grid.cpp Adds GRDECL grid keyword size validation and overflow checks before allocation/usage.
Comments suppressed due to low confidence (2)

lib/resdata/rd_kw_grdecl.cpp:232

  • buffer_size was increased to 256 and the numeric scans use %128g/%128lg, but token input is still limited by fscanf(stream, "%32s", buffer). As a result long numeric tokens are still truncated and the new buffer size/scan widths are ineffective; consider updating the fscanf width to match the allocated buffer (or remove the unused buffer_size indirection).
    char newline = '\n';
    bool atEOF = false;
    size_t init_size = 32;
    size_t buffer_size = 256;
    size_t data_index = 0;
    int sizeof_ctype = rd_type_get_sizeof_ctype(data_type);
    size_t data_size = init_size;
    char *buffer = (char *)util_calloc((buffer_size + 1), sizeof *buffer);
    char *data = (char *)util_calloc(sizeof_ctype * data_size, sizeof *data);

    while (true) {
        if (fscanf(stream, "%32s", buffer) == 1) {
            if (strcmp(buffer, RD_COMMENT_STRING) == 0) {
                // We have read a comment marker - just read up to the end of line.

python/resdata/resfile/rd_kw.py:1094

  • numpy_view() now special-cases len(self)==0 to return an empty array, which changes behavior from the previous pointer-cast path. There are tests for numpyView() on non-empty keywords but none for the empty case; please add one to ensure this stays safe and returns the expected dtype.

        if len(self):
            ap = ctypes.cast(self.data_ptr, ctypes.POINTER(ct * len(self)))
            return np.frombuffer(ap.contents, dtype=self.dtype)
        else:
            return np.array([], dtype=self.dtype)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/resdata/rd_grid.cpp
Comment thread lib/resdata/rd_grid.cpp
Comment thread lib/resdata/rd_grid.cpp Outdated
Comment thread lib/resdata/rd_kw.cpp
Comment thread python/resdata/resfile/rd_kw.py
Co-authored-by: Alexander Jaust <18347253+ajaust@users.noreply.github.com>
Fixing some bugs in the model test surfaced these bugs.
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