From 4d0f5ab1a8b3ade61a160ac8b5ecf49ee6bed1e5 Mon Sep 17 00:00:00 2001 From: Youwei Song Date: Tue, 26 Nov 2019 21:30:08 +0800 Subject: [PATCH] add axis check for concat op (#21288) * add axis check for concat op test=develop * fix PADDLE_ENFORCE format test=develop * move to ComputeAxis for InferShape check test=develop --- paddle/fluid/operators/concat_op.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/paddle/fluid/operators/concat_op.h b/paddle/fluid/operators/concat_op.h index 8613b5e3c8..e00d606f64 100644 --- a/paddle/fluid/operators/concat_op.h +++ b/paddle/fluid/operators/concat_op.h @@ -61,6 +61,11 @@ static inline framework::DDim ComputeAndCheckShape( } static inline int64_t ComputeAxis(int64_t axis, int64_t rank) { + PADDLE_ENFORCE_EQ( + axis >= -rank && axis < rank, true, + platform::errors::InvalidArgument( + "The axis is expected to be in range of [%d, %d), but got %d", -rank, + rank, axis)); if (axis < 0) { axis = axis + rank; } -- GitLab