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

Commit

Permalink
fix for large decoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Dec 21, 2017
1 parent 939a45b commit d1c27a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ htmlcov/
/*.txt
/*.whl
/xdelta3/lib/
/tests/b1.bin
/tests/b2.bin
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install:
- gcc -v
#- docker pull $DOCKER_IMAGE
- pip freeze
- make download-test-files

script:
- make test
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ lint:
flake8 xdelta3/ tests/
pytest xdelta3 -p no:sugar -q

.PHONY: download-test-files
download-test-files:
curl -sL https://github.com/samuelcolvin/xdelta3-python/files/1579377/files.zip > test_html.zip
echo "52bf4ee680a86afdeed9aad30e7d68fa test_html.zip" > test_html.zip.md5
md5sum -c test_html.zip.md5
unzip -o test_html.zip
mv b1.bin b2.bin tests
rm test_html.zip test_html.zip.md5

.PHONY: test
test: install
pytest --cov=xdelta3
Expand Down
14 changes: 14 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import os
import string
from pathlib import Path

import pytest

Expand Down Expand Up @@ -64,3 +65,16 @@ def test_readme():

value_two_rebuilt = xdelta3.decode(value_one, delta)
assert value_two_rebuilt == value_two


def test_large_decode():
this_dir = Path(__file__).parent
try:
b1 = (this_dir / 'b1.bin').read_bytes()
b2 = (this_dir / 'b2.bin').read_bytes()
except FileNotFoundError as e:
raise RuntimeError('file required for test not found, run `make download-test-files`') from e

d = xdelta3.encode(b1, b2)
b3 = xdelta3.decode(b1, d)
assert b2 == b3
2 changes: 1 addition & 1 deletion xdelta3/_xdelta3.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
output_buf, &output_size, output_alloc, flags);
} else {
// output shouldn't be bigger than the original plus the delta, but give a little leeway
output_alloc = input_size + source_size * 11 / 10;
output_alloc = input_size + source_size * 2;
output_buf = main_malloc(output_alloc);
result = xd3_decode_memory(input_bytes, input_size, source_bytes, source_size,
output_buf, &output_size, output_alloc, flags);
Expand Down

0 comments on commit d1c27a6

Please sign in to comment.