Skip to content

Fix serialization buffer type#6927

Merged
bangerth merged 1 commit intogeodynamics:mainfrom
gassmoeller:fix_serialization_buffer_type
Apr 18, 2026
Merged

Fix serialization buffer type#6927
bangerth merged 1 commit intogeodynamics:mainfrom
gassmoeller:fix_serialization_buffer_type

Conversation

@gassmoeller
Copy link
Copy Markdown
Member

So with all the talk about AI tools finding memory issues in existing software, I thought I ask Codex to take a look at ASPECT. This is the first thing it found (I may open a few more PRs, just need to review the cases).

The main issue here is that the compressed_data buffer was set up as std::vector<char *>, while it should have been std::vector<Bytef> (Bytef is a zlib defined type which is just unsigned char). This usually works, because a pointer is usually equally sized or larger than a char, but it is a wrong type nevertheless. The new code is also easier to read, and avoids repeated calls to str() which creates copies of the buffer content. The unusual type names are zlib internal typedefs.

Copy link
Copy Markdown
Contributor

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Yes, nice job. Please make the one variable const and then merge yourself!

uLongf compressed_data_length = compressBound (oss.str().length());
std::vector<char *> compressed_data (compressed_data_length);
int err = compress2 (reinterpret_cast<Bytef *>(&compressed_data[0]),
const std::string serialized_data = oss.str();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At first I thought it's a bummer that you need to create a copy of the string, but oss.str() returns the string by value, not by reference, so this is actually more efficient. Nice catch!

Comment thread source/simulator/checkpoint_restart.cc
@bangerth
Copy link
Copy Markdown
Contributor

The spherical_nsinker_gmg_gc test fails. Do you have that locally as well?

@bangerth
Copy link
Copy Markdown
Contributor

Same test as elsewhere. I think it's safe to assume that this patch isn't responsible for the failing test, so please merge once you made the variable const.

@tjhei
Copy link
Copy Markdown
Member

tjhei commented Apr 12, 2026

Same test as elsewhere.

how can this test require two additional empty lines and succeed in the Jenkins tester?!

@gassmoeller
Copy link
Copy Markdown
Member Author

I dont know what is happening with the failing test, I cannot reproduce this locally. If I run the test in the docker container everything passes as expected (both on this branch and on main). I have retriggered the tester, lets see if that fixes it.

Can you make this variable const?

Unfortunately, I cant. It is an input and output variable of compress2. On input it contains the buffer size (which was chosen as the maximum possible buffer size compress2 might need). On output it contains the actual buffer size that was filled by compress2.

I will wait for the tester before merging. Maybe it will also help to just replace that file with a fresh reference solution, maybe something is weird about the whitespace in the file (although it wouldnt explain why Jenkins doesnt complain). The only difference between Jenkins and Github actions is the operating system and git version that does the initial checkout of the repository (and one of them merges with main, while the other doesnt).

uLongf compressed_data_length = compressBound(serialized_data_length);
std::vector<Bytef> compressed_data(compressed_data_length);
int err = compress2 (compressed_data.data(),
&compressed_data_length,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see. One would have imagined that that's an input argument, but I recognize now that it's in/out. Never mind then.

@bangerth
Copy link
Copy Markdown
Contributor

Since the issue isn't just with this PR, something is going on that is the same for all PRs. Did we merge something bad?

@gassmoeller
Copy link
Copy Markdown
Member Author

Did we merge something bad?

It started around #6928 and #6929, but I cant see a connection. Also the Jenkins tester is fine, while the Github actions tester that builds on the same docker image fails. My suspicion is that something changed in the Github action tester base stack (ubuntu-latest) that runs our tester image. But the only thing that happens there is to check out the repository and mount it into our tester image. And I dont understand why only some tests are affected.

I could try opening a PR that reverts the two PRs and check if the tests pass then.

@bangerth
Copy link
Copy Markdown
Contributor

Let's merge here. Feel free to try and see whether reverting the two other PRs fixes things.

@bangerth bangerth merged commit 761cc61 into geodynamics:main Apr 18, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants