Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vt] fix for crash when creating VtArray from large python buffer #2064

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pxr/base/vt/arrayPyBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@ Vt_ArrayFromBuffer(TfPyObjWrapper const &obj,
// Check that the number of elements matches.
auto multiply = [](Py_ssize_t x, Py_ssize_t y) { return x * y; };
auto numItems = std::accumulate(
view.shape, view.shape + view.ndim, 1, multiply);
view.shape, view.shape + view.ndim, (Py_ssize_t)1, multiply);

// Compute the total # of items in one element.
auto elemShape = Vt_GetElementShape<T>();
auto elemSize = std::accumulate(
elemShape.begin(), elemShape.end(), 1, multiply);
elemShape.begin(), elemShape.end(), (Py_ssize_t)1, multiply);

// Sanity check data sizes.
auto arraySize = numItems / elemSize;
Expand Down
16 changes: 13 additions & 3 deletions pxr/base/vt/testenv/testVtArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# pylint: disable=range-builtin-not-iterating
#
from __future__ import division

import array
import unittest
import sys, math
from pxr import Gf, Vt
Expand Down Expand Up @@ -157,10 +159,10 @@ def test_Overflows(self):
for arrayType, (x0, x1) in overflows:
for x in (x0, x1):
with self.assertRaises(OverflowError):
array = arrayType((x,))
arrayT = arrayType((x,))
for x in (x0+1, x1-1):
array = arrayType((x,))
self.assertEqual(array, eval(repr(array)))
arrayT = arrayType((x,))
self.assertEqual(arrayT, eval(repr(arrayT)))

def test_ParallelizedOps(self):
m0 = Vt.Matrix4dArray((Gf.Matrix4d(1),Gf.Matrix4d(2)))
Expand Down Expand Up @@ -357,6 +359,14 @@ def _TestDivision(ArrayType, QuatType, ImgType):
_TestDivision(Vt.QuatdArray, Gf.Quatd, Gf.Vec3d)
_TestDivision(Vt.QuaternionArray, Gf.Quaternion, Gf.Vec3d)

def test_LargeBuffer(self):
'''VtArray can be created from a buffer with item count
greater than maxint'''
largePyBuffer = array.array('B', (0,)) * 2500000000
vtArrayFromBuffer = Vt.UCharArray.FromBuffer(largePyBuffer)
self.assertEqual(len(vtArrayFromBuffer), 2500000000)


if __name__ == '__main__':
unittest.main()