Skip to content

STL writer: copy at most the hash into the 80-byte header - #460

Open
dylanoliverdo-coder wants to merge 1 commit into
CauldronDevelopmentLLC:masterfrom
dylanoliverdo-coder:fix-stl-header-overread
Open

dylanoliverdo-coder wants to merge 1 commit into
CauldronDevelopmentLLC:masterfrom
dylanoliverdo-coder:fix-stl-header-overread

Conversation

@dylanoliverdo-coder

Copy link
Copy Markdown

Writer::writeHeader copied 80 bytes from the hash string with memcpy(header, hash.c_str(), 80). The hash is shorter than 80 bytes, so this read past the end of the string. Two runs of the same job wrote identical triangles but different header bytes, so the files differed.

Fix: copy min(hash.size(), 80) bytes into the zero-filled header (adds #include <algorithm>). The hash itself stays in the header.

Check: the same job, cut twice, gives byte-identical files with this change. On master the whole-file hash changes from run to run while the triangle bytes (from byte 80 on) match.

Tests: the tests/testHarness gcodetool suites pass 15 of 15 on master and on this branch.

🤖 Generated with Claude Code

The header copied 80 bytes from the hash string, which is shorter than
80 bytes, so it read past the end of the string.  Two runs of the same
job wrote the same triangles but different header bytes, and so
different files.
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.

1 participant