From a7596ef6dee06ef3dfd1d9ae7ef05ea8b46de636 Mon Sep 17 00:00:00 2001 From: nashit hayyat Date: Tue, 11 Aug 2026 15:57:32 +0530 Subject: [PATCH] check buffer_constraints size against dimensions in Parameter ctor --- src/Parameter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Parameter.cpp b/src/Parameter.cpp index 635b924f1482..76f43177f495 100644 --- a/src/Parameter.cpp +++ b/src/Parameter.cpp @@ -88,6 +88,14 @@ Parameter::Parameter(const Type &t, int dimensions, const std::string &name, const Buffer &buffer, int host_alignment, const std::vector &buffer_constraints, MemoryType memory_type) : contents(new Internal::ParameterContents(t, /*is_buffer*/ true, dimensions, name)) { + // Every other constructor keeps buffer_constraints sized to the + // dimensionality, and check_dim_ok() relies on that when indexing it. This + // reconstruction path takes the vector verbatim, so a serialized pipeline + // claiming more dimensions than it carries constraints for would let the + // constraint accessors read past the vector. + user_assert(buffer_constraints.size() == (size_t)std::max(0, dimensions)) + << "Buffer Parameter " << name << " has " << dimensions + << " dimensions but " << buffer_constraints.size() << " dimension constraints\n"; contents->buffer = buffer; contents->host_alignment = host_alignment; contents->buffer_constraints = buffer_constraints;