lib: unpack size_t values safely - #569
Conversation
|
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.
There was a problem hiding this comment.
fixed in 8bfb0ad. the overflow test now uses assert_err.
|
@claude review |
Claude review of PR #569 (8bfb0ad)Suggestions
Nits(None beyond what the maintainer already flagged: use CLAUDE.md improvements(None identified) |
ed5232e to
8bfb0ad
Compare
|
@qdeslandes : updated in 8bfb0ad: rebased on current |
| #if SIZE_MAX < UINT64_MAX | ||
| static void rpack_size_t_overflow(void **state) | ||
| { | ||
| _free_bf_wpack_ bf_wpack_t *wpack = NULL; | ||
| _free_bf_rpack_ bf_rpack_t *rpack = NULL; | ||
| const void *data; | ||
| size_t data_len; | ||
| bf_rpack_node_t root; | ||
| size_t size_val = 0; | ||
|
|
||
| (void)state; | ||
|
|
||
| assert_ok(bf_wpack_new(&wpack)); | ||
| bf_wpack_kv_u64(wpack, "size_val", (uint64_t)SIZE_MAX + 1); | ||
| assert_ok(bf_wpack_get_data(wpack, &data, &data_len)); | ||
|
|
||
| assert_ok(bf_rpack_new(&rpack, data, data_len)); | ||
| root = bf_rpack_root(rpack); | ||
|
|
||
| assert_err(bf_rpack_kv_size(root, "size_val", &size_val)); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Move if SIZE_MAX < UINT64_MAX within the function's body, so it (the check) can be removed from the tests array.
There was a problem hiding this comment.
done in 7f5362e. the guard is now inside the test body.
|
@claude review |
Read packed sizes through uint64_t to preserve the wire format. Reject values that do not fit in size_t on 32-bit targets.
8bfb0ad to
7f5362e
Compare
|
@qdeslandes is it ready to be merged now? |
Summary
size_tunpack helper while preserving theuint64_twire formatSIZE_MAXand update the affected unpack call sitesFixes #548