Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backends/xnnpack/runtime/XNNCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ Error defineTensor(
ET_CHECK_OR_RETURN_ERROR(
tensor_value != nullptr, InvalidProgram, "Deserialized tensor is null");

// Validate that tensor_value->flags() is a subset of the allowed flags.
constexpr uint32_t kAllowedFlagsMask =
XNN_VALUE_FLAG_EXTERNAL_INPUT | XNN_VALUE_FLAG_EXTERNAL_OUTPUT;
ET_CHECK_OR_RETURN_ERROR(
(tensor_value->flags() & ~kAllowedFlagsMask) == 0,
InvalidProgram,
"Tensor value has unsupported flag bits 0x%x",
tensor_value->flags());
Comment on lines +325 to +329
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The error log uses printf formatting; passing tensor_value->flags() (a FlatBuffers uint, i.e., uint32_t) to 0x%x can be undefined on platforms where uint32_t is not unsigned int (e.g., typedefs to unsigned long). Cast to the matching type or use an inttypes.h macro (e.g., print 0x%" PRIx32 "). Also consider logging the unsupported bits value (flags & ~kAllowedFlagsMask) rather than the full flags to make the message actionable.

Copilot uses AI. Check for mistakes.

// Get tensor dims, here we need to use a vector in order to properly
// convert the uint32_t* to size_t*. Scalar tensors (rank 0) are permitted
// to have a null dims vector; in that case dims_data is empty.
Expand Down
Loading