lib: unpack size_t values safely - #569
Conversation
Add a typed size_t reader so 32-bit builds stop passing size_t pointers to the uint64 unpack API while keeping the on-wire format as uint64. Reject packed values above SIZE_MAX and switch only the affected size_t unpack call sites and focused tests to the new helper.
|
Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Hi, could you please disclose if/how much AI has been used for this work? Thank you. |
|
Hi @qdeslandes , I used AI to help with the initial understanding & investigation (searching the relevant unpack call sites etc) and used it to draft an initial version of the patch. I reviewed and edited the diff, reproduced the incompatible-pointer-type issue from the reported 32-bit build failure, verified the size_t to uint64_t conversion and overflow behavior across the affected unpack sites, and I own the final submission. |
Thank you for this answer. Did you build and run the code? Did you run the tests? Did you sign the CLA? |
08a14cb to
3f6db8a
Compare
Yes. I built and tested the updated branch in a fresh privileged Fedora 44 environment. Results: build completed successfully The CLA is signed as well. |
|
@qdeslandes The CLA check is green and the branch is up to date with When you have a chance, could you please review the patch? @sudipm-mukherjee, if convenient, could you confirm that the current branch resolves the i386 package build reported in #548? |
|
hi @qdeslandes, could you please take another look when you have a chance? the cla is green, the branch is mergeable, and all local checks passed; if everything looks good, could you please merge it? thank you. |
sorry was busy with $dayjob. I will try to check it tonight. |
| assert_ok(bf_rpack_new(&rpack, data, data_len)); | ||
| root = bf_rpack_root(rpack); | ||
|
|
||
| assert_int_equal(bf_rpack_kv_size(root, "size_val", &size_val), -EOVERFLOW); |
There was a problem hiding this comment.
assert_err would be better, so we ensure the call fails, but we don't freeze a specific errno value.
|
@claude review |
Claude review of PR #569 (b7740f0)Suggestions
Nits(None beyond what the maintainer already flagged: use CLAUDE.md improvements(None identified) |
| if (r) | ||
| return r; | ||
|
|
||
| if (_value > SIZE_MAX) |
There was a problem hiding this comment.
Claude: suggestion: On 64-bit platforms where SIZE_MAX == UINT64_MAX, this comparison is tautologically false — a uint64_t can never exceed UINT64_MAX. With -Wall -Wextra (enabled in CMakeLists.txt:63), GCC may emit a -Wtype-limits warning.
The test file already uses #if SIZE_MAX < UINT64_MAX to guard the overflow test. Wrapping this check with the same guard keeps them consistent and eliminates dead code on 64-bit:
#if SIZE_MAX < UINT64_MAX
if (_value > SIZE_MAX)
return -EOVERFLOW;
#endif
Summary
size_tunpack helper while preserving theuint64_twire formatSIZE_MAXand update the affected unpack call sitesFixes #548