Skip to content

Commit 74828be

Browse files
Brennan Vincentfacebook-github-bot
authored andcommitted
fix segfault in cat on CPU with tensors that can't be indexed with 32-bit ints. (#21530)
Summary: Should be self-explanatory. This `int` variable is overflowing. Reported in #21526 Pull Request resolved: #21530 Differential Revision: D15719275 Pulled By: umanwizard fbshipit-source-id: 24e917a00a5b78bc3af29ef3b8b72eea7e89d5d5
1 parent 4063746 commit 74828be

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

aten/src/TH/generic/THTensor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void THTensor_(catArray)(THTensor *result, THTensor **inputs, int numInputs, int
799799
if (!should_skip(inputs[j])) {
800800
THTensor* input0 = inputs[j];
801801
scalar_t* input0_data = THStorage_(data)(THTensor_getStoragePtr(input0)) + input0->storage_offset();
802-
int local_inner = inner * input0->size(dimension);
802+
int64_t local_inner = inner * input0->size(dimension);
803803
if (local_inner != 0) {
804804
memcpy(result_data + offset, input0_data + o*local_inner, local_inner*sizeof(scalar_t));
805805
} // input0_size != 0

test/test_torch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,6 +4948,16 @@ def _test_cat_empty(self, use_cuda=False):
49484948
def test_cat_empty(self):
49494949
self._test_cat_empty(self)
49504950

4951+
@slowTest
4952+
def test_cat_big(self):
4953+
SIZE1 = 6500
4954+
SIZE2 = 4500
4955+
concat_list = []
4956+
concat_list.append(torch.ones((SIZE1, 1024 * 512), dtype=torch.uint8))
4957+
concat_list.append(torch.ones((SIZE2, 1024 * 512), dtype=torch.uint8))
4958+
result = torch.cat(concat_list)
4959+
self.assertEqual(result.size(0), SIZE1 + SIZE2)
4960+
49514961
def test_narrow(self):
49524962
x = torch.Tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
49534963
self.assertEqual(x.narrow(0, 0, 1), torch.Tensor([[0, 1, 2]]))

0 commit comments

Comments
 (0)