Skip to content

Commit

Permalink
[Storage] Fix CRC64 extension with large data (Azure#39655)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalauzon-msft authored Feb 18, 2025
1 parent 95ed0a7 commit cbfb46e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PyObject* compute(PyObject* self, PyObject* args) {
if (!PyArg_ParseTuple(args, "y#K", &src, &length, &uCrc))
return NULL;

int pData = 0;
uint64_t pData = 0;
uint64_t uSize = (uint64_t)length;
uint64_t uBytes, uStop;

Expand All @@ -25,12 +25,12 @@ PyObject* compute(PyObject* self, PyObject* args) {
uStop = uSize - (uSize % 32);
if (uStop >= 2 * 32)
{
uint64_t uCrc0 = 0ULL;
uint64_t uCrc1 = 0ULL;
uint64_t uCrc2 = 0ULL;
uint64_t uCrc3 = 0ULL;
uint64_t uCrc0 = 0;
uint64_t uCrc1 = 0;
uint64_t uCrc2 = 0;
uint64_t uCrc3 = 0;

int pLast = pData + (int)uStop - 32;
uint64_t pLast = pData + uStop - 32;
uSize -= uStop;
uCrc0 = uCrc;

Expand Down
9 changes: 7 additions & 2 deletions sdk/storage/azure-storage-extensions/tests/test_crc64.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ def test_compute(data, initial, expected):
actual = crc64.compute(data, initial)
assert actual == expected

def test_compute_chunks():
data = os.urandom(4 * 1024 * 1024)
@pytest.mark.parametrize("size", [1024, 4 * 1024 * 1024, 1 * 1024 * 1024 * 1024, 3 * 1024 * 1024 * 1024])
def test_compute_chunks(size):
data = b''
while len(data) < size:
length = min(size - len(data), 1 * 1024 * 1024 * 1024)
data += os.urandom(length)

chunk_size = 1024 * 1024
full_crc = crc64.compute(data, 0)

Expand Down

0 comments on commit cbfb46e

Please sign in to comment.