Skip to content

lib: unpack size_t values safely - #569

Open
verma-divyanshu-git wants to merge 3 commits into
facebook:mainfrom
verma-divyanshu-git:fix-548-i386-size-t-unpack
Open

lib: unpack size_t values safely#569
verma-divyanshu-git wants to merge 3 commits into
facebook:mainfrom
verma-divyanshu-git:fix-548-i386-size-t-unpack

Conversation

@verma-divyanshu-git

@verma-divyanshu-git verma-divyanshu-git commented Jul 17, 2026

Copy link
Copy Markdown

Summary

  • add a typed size_t unpack helper while preserving the uint64_t wire format
  • reject packed values above SIZE_MAX and update the affected unpack call sites
  • add focused unit coverage for normal and overflowing values

Fixes #548

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.
@meta-cla

meta-cla Bot commented Jul 17, 2026

Copy link
Copy Markdown

Hi @verma-divyanshu-git!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@qdeslandes

Copy link
Copy Markdown
Contributor

Hi, could you please disclose if/how much AI has been used for this work? Thank you.

@verma-divyanshu-git

Copy link
Copy Markdown
Author

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.

@qdeslandes

Copy link
Copy Markdown
Contributor

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?

@meta-cla meta-cla Bot added the cla signed label Jul 17, 2026
@verma-divyanshu-git
verma-divyanshu-git force-pushed the fix-548-i386-size-t-unpack branch from 08a14cb to 3f6db8a Compare July 17, 2026 20:40
@verma-divyanshu-git

Copy link
Copy Markdown
Author

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?

Yes. I built and tested the updated branch in a fresh privileged Fedora 44 environment.

Results:

build completed successfully
unit tests: 23/23 passed
e2e tests: 93/93 passed
integration tests: 2/2 passed
formatting/static checks: 4/4 passed
coverage target completed successfully

The CLA is signed as well.

@verma-divyanshu-git

Copy link
Copy Markdown
Author

@qdeslandes The CLA check is green and the branch is up to date with main.

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?

@verma-divyanshu-git

Copy link
Copy Markdown
Author

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.

@sudipm-mukherjee

Copy link
Copy Markdown
Contributor

@sudipm-mukherjee, if convenient, could you confirm that the current branch resolves the i386 package build reported in #548?

sorry was busy with $dayjob. I will try to check it tonight.

@qdeslandes qdeslandes left a comment

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.

LGTM, except for a couple of nits:

  • This PR could be a single commit (72 chars wide)
  • Remove the merge commit

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);

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.

assert_err would be better, so we ensure the call fails, but we don't freeze a specific errno value.

@qdeslandes

Copy link
Copy Markdown
Contributor

@claude review

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Claude review of PR #569 (b7740f0)

Suggestions

  • Guard tautological SIZE_MAX comparisonsrc/libbpfilter/pack.c:546 — On 64-bit, _value > SIZE_MAX is always false and may trigger -Wtype-limits; wrap with #if SIZE_MAX < UINT64_MAX like the test already does

Nits

(None beyond what the maintainer already flagged: use assert_err in the overflow test, squash to single commit)

CLAUDE.md improvements

(None identified)

Workflow run

Comment thread src/libbpfilter/pack.c
if (r)
return r;

if (_value > SIZE_MAX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

Fails to build in i386

3 participants