Skip to content
This repository was archived by the owner on Apr 23, 2022. It is now read-only.

Commit d1c27a6

Browse files
committed
fix for large decoded value
1 parent 939a45b commit d1c27a6

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ htmlcov/
1313
/*.txt
1414
/*.whl
1515
/xdelta3/lib/
16+
/tests/b1.bin
17+
/tests/b2.bin

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ install:
2828
- gcc -v
2929
#- docker pull $DOCKER_IMAGE
3030
- pip freeze
31+
- make download-test-files
3132

3233
script:
3334
- make test

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ lint:
2323
flake8 xdelta3/ tests/
2424
pytest xdelta3 -p no:sugar -q
2525

26+
.PHONY: download-test-files
27+
download-test-files:
28+
curl -sL https://github.com/samuelcolvin/xdelta3-python/files/1579377/files.zip > test_html.zip
29+
echo "52bf4ee680a86afdeed9aad30e7d68fa test_html.zip" > test_html.zip.md5
30+
md5sum -c test_html.zip.md5
31+
unzip -o test_html.zip
32+
mv b1.bin b2.bin tests
33+
rm test_html.zip test_html.zip.md5
34+
2635
.PHONY: test
2736
test: install
2837
pytest --cov=xdelta3

tests/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import os
33
import string
4+
from pathlib import Path
45

56
import pytest
67

@@ -64,3 +65,16 @@ def test_readme():
6465

6566
value_two_rebuilt = xdelta3.decode(value_one, delta)
6667
assert value_two_rebuilt == value_two
68+
69+
70+
def test_large_decode():
71+
this_dir = Path(__file__).parent
72+
try:
73+
b1 = (this_dir / 'b1.bin').read_bytes()
74+
b2 = (this_dir / 'b2.bin').read_bytes()
75+
except FileNotFoundError as e:
76+
raise RuntimeError('file required for test not found, run `make download-test-files`') from e
77+
78+
d = xdelta3.encode(b1, b2)
79+
b3 = xdelta3.decode(b1, d)
80+
assert b2 == b3

xdelta3/_xdelta3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
2727
output_buf, &output_size, output_alloc, flags);
2828
} else {
2929
// output shouldn't be bigger than the original plus the delta, but give a little leeway
30-
output_alloc = input_size + source_size * 11 / 10;
30+
output_alloc = input_size + source_size * 2;
3131
output_buf = main_malloc(output_alloc);
3232
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
3333
output_buf, &output_size, output_alloc, flags);

0 commit comments

Comments
 (0)