Skip to content

Fix double-scaled pointer arithmetic in ETDumpGen constructor #18782

Open
lucylq wants to merge 1 commit intomainfrom
security32
Open

Fix double-scaled pointer arithmetic in ETDumpGen constructor #18782
lucylq wants to merge 1 commit intomainfrom
security32

Conversation

@lucylq
Copy link
Copy Markdown
Contributor

@lucylq lucylq commented Apr 8, 2026

builder_ + sizeof(struct flatcc_builder) results in builder_ + sizeof(struct flatcc_builder) * sizeof(struct flatcc_builder)

Because C/C++ arithmetic builder_ + N advances by N*sizeof(type) where type is the type of builder_. This means we get a pointer that advances past the intended memory location, potentially into unallocated memory.

Replace with builder_ + 1, which correctly advances by exactly one sizeof(struct flatcc_builder) element.

This PR was authored with the assistance of Claude.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 8, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18782

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 3 New Failures, 2 Unrelated Failures

As of commit 3d9d308 with merge base 21d9c64 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 8, 2026
@lucylq lucylq marked this pull request as ready for review April 8, 2026 22:27
@lucylq lucylq requested a review from Gasoonjia as a code owner April 8, 2026 22:27
Copilot AI review requested due to automatic review settings April 8, 2026 22:27
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an incorrect pointer-arithmetic expression in ETDumpGen’s constructor that could advance the builder pointer far beyond the intended location when computing the start of the aligned buffer region.

Changes:

  • Replace builder_ + sizeof(struct flatcc_builder) with builder_ + 1 to avoid double-scaling in typed pointer arithmetic.
  • Preserve the intended “advance by one builder struct, then align” behavior when computing buffer_with_builder.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

(struct flatcc_builder*)internal::align_pointer(buffer.data(), 64);
uintptr_t buffer_with_builder = (uintptr_t)internal::align_pointer(
builder_ + sizeof(struct flatcc_builder), 64);
builder_ + 1, 64);
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.

why are we advancing the pointer at all?

Copy link
Copy Markdown
Contributor Author

@lucylq lucylq Apr 9, 2026

Choose a reason for hiding this comment

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

I think there's separate memory to hold the flatcc_builder which has context to build the flatbuffer, and then the working arena.

…ECUTORCH-32)

The expression `builder_ + sizeof(struct flatcc_builder)` double-scales
the offset because `builder_` is a `struct flatcc_builder*` -- the
compiler already multiplies by `sizeof(struct flatcc_builder)` for typed
pointer arithmetic. The result advances far past the intended location,
potentially into unallocated memory.

Replace with `builder_ + 1`, which correctly advances by exactly one
`sizeof(struct flatcc_builder)` element.

This PR was authored with the assistance of Claude.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants