Skip to content

Use FlatTensorHeader::kHeaderOffset for the FlatTensor size check - #22137

Open
shoumikhin wants to merge 1 commit into
mainfrom
flat-tensor-header-offset
Open

Use FlatTensorHeader::kHeaderOffset for the FlatTensor size check#22137
shoumikhin wants to merge 1 commit into
mainfrom
flat-tensor-header-offset

Conversation

@shoumikhin

Copy link
Copy Markdown
Contributor

Summary

FlatTensorDataMap::load checks that the buffer is at least as long as the flatbuffer header before it reads the root table offset out of it. It computed that length as sizeof(flatbuffers::uoffset_t) + flatbuffers::kFileIdentifierLength.

kFileIdentifierLength only exists at namespace scope in newer flatbuffers releases. In flatbuffers 1.12 the same constant exists only as a member of FlatBufferBuilder, so a build against an older flatbuffers fails to compile:

flat_tensor_data_map.cpp:303:40: error: no member named 'kFileIdentifierLength' in namespace 'flatbuffers'

The submodule pinned in this repository is v24.3.25, where the namespace scope name does exist, so CI here cannot see the problem.

What this changes

The number being computed is 8: a 4 byte root table offset followed by a 4 byte file identifier. FlatTensorHeader::kHeaderOffset already names exactly that number, because the FlatTensor header begins right after the flatbuffer header ends. The matching bounds check in Program::load already uses ExtendedHeader::kHeaderOffset for the same reason.

So this swaps the expression for FlatTensorHeader::kHeaderOffset. The bound does not move, behavior is unchanged, and no include is added, flat_tensor_header.h was already included by this file.

Test plan

Compiled extension/flat_tensor/flat_tensor_data_map.cpp with -std=c++17 -Wall against the pinned flatbuffers v24.3.25. Clean, no warnings and no errors.

Checked that the fix is load bearing by compiling both spellings against both flatbuffers versions:

old expression new expression
flatbuffers 1.12.0 fails with the error above compiles
flatbuffers 24.3.25 compiles compiles

The probe also static_asserts that the new expression equals the old one and equals 8, so the two spellings really do produce the same bound.

The minimum size check in `FlatTensorDataMap::load` spelled the size of
the flatbuffer header as `sizeof(flatbuffers::uoffset_t)` plus
`flatbuffers::kFileIdentifierLength`.

`kFileIdentifierLength` only exists at namespace scope in newer
flatbuffers releases. In flatbuffers 1.12 the same constant exists only
as a member of `FlatBufferBuilder`, so a build against an older
flatbuffers fails to compile:

```
error: no member named 'kFileIdentifierLength' in namespace 'flatbuffers'
```

The number being computed is 8: a 4 byte root table offset followed by a
4 byte file identifier. `FlatTensorHeader::kHeaderOffset` already names
exactly that number, because the FlatTensor header starts right after
the flatbuffer header ends. The equivalent bounds check in
`Program::load` already uses `ExtendedHeader::kHeaderOffset` for the
same reason.

Use `FlatTensorHeader::kHeaderOffset` here too. The bound does not move,
behavior is unchanged, and no new include is needed because
`flat_tensor_header.h` was already included.
Copilot AI lite review requested due to automatic review settings August 25, 2026 06:16
@pytorch-bot

pytorch-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Pending

As of commit 3b175d0 with merge base 88a5f60 (image):

NEW FAILURE - The following job has failed:

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 Aug 25, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@shoumikhin shoumikhin added the release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs label Aug 25, 2026
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. release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants