Skip to content

Commit d559b88

Browse files
committed
[None][fix] Enhancing code robustness and adding boundary checks for ITensor
Signed-off-by: fanyunfan <[email protected]>
1 parent a35c38f commit d559b88

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cpp/include/tensorrt_llm/runtime/iTensor.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ITensor : virtual public IBuffer
7171
[[nodiscard]] DimType64 getDimension() const
7272
{
7373
auto const shape = getShape();
74-
static_assert(n < shape.MAX_DIMS && n >= -shape.MAX_DIMS,
74+
static_assert(n < Shape::MAX_DIMS && n >= -Shape::MAX_DIMS,
7575
"Trying to access the dimension of a tensor, when its maximal shape cannot have that dimension.");
7676
if constexpr (n < 0)
7777
{
@@ -126,6 +126,11 @@ class ITensor : virtual public IBuffer
126126
{
127127
auto const vol = volume(shape);
128128
TLLM_CHECK_WITH_INFO(0 <= vol, "Invalid tensor shape");
129+
if constexpr (sizeof(std::size_t) == 4)
130+
{
131+
TLLM_CHECK_WITH_INFO(vol <= static_cast<std::int64_t>(std::numeric_limits<std::size_t>::max()),
132+
"Tensor volume exceeds 32-bit size_t maximum capacity.");
133+
}
129134
return static_cast<std::size_t>(vol);
130135
}
131136

0 commit comments

Comments
 (0)