From f0b7c8d8274b7df334890203df24773f4a51ee60 Mon Sep 17 00:00:00 2001 From: nashit hayyat Date: Mon, 23 Nov 2026 14:55:24 +0530 Subject: [PATCH] bounds-check the padding tensor shape in hannk PadOp PadOp indexes the padding tensor's buffer using the operand rank, in both map_bounds (padding(0, d)) and execute (padding_buf(0/1, idx)), guarded only by assert(). In a release build a .tflite model whose PAD padding tensor is not shaped [2, rank] reads past the padding buffer, which points directly at the model's flatbuffer bytes. Check the padding shape and the input/output ranks in the PadOp constructor, so both the tflite parser and the delegate are covered. Well-formed models are unaffected. --- apps/hannk/interpreter/ops.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/hannk/interpreter/ops.h b/apps/hannk/interpreter/ops.h index 9dc700e08dd9..6fde9e56840e 100644 --- a/apps/hannk/interpreter/ops.h +++ b/apps/hannk/interpreter/ops.h @@ -285,6 +285,9 @@ class PadOp : public Op { public: PadOp(const TensorPtr &input, const TensorPtr &padding, const TensorPtr &output) : Op({input, padding}, {output}) { + HCHECK(padding->rank() == 2 && padding->extent(0) == 2 && + padding->extent(1) == input->rank() && output->rank() == input->rank()) + << "Pad requires a [2, rank] padding tensor matching the input and output ranks\n"; if (input->rank() == 0 || !padding->is_constant()) { output->set_dynamic(); }