Mercurial > public > mercurial-scm > hg-stable
view contrib/python-zstandard/tests/test_cffi.py @ 30830:08fa3a76a080
zstd: prevent potential free() of uninitialized memory
This is a cherry pick of an upstream fix. The free() of uninitialed
memory could likely only occur if a malloc() inside zstd fails.
The patched functions aren't currently used by Mercurial. But I don't
like leaving footguns sitting around.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 17 Jan 2017 10:17:13 -0800 |
parents | b86a448a2965 |
children |
line wrap: on
line source
import io try: import unittest2 as unittest except ImportError: import unittest import zstd try: import zstd_cffi except ImportError: raise unittest.SkipTest('cffi version of zstd not available') class TestCFFIWriteToToCDecompressor(unittest.TestCase): def test_simple(self): orig = io.BytesIO() orig.write(b'foo') orig.write(b'bar') orig.write(b'foobar' * 16384) dest = io.BytesIO() cctx = zstd_cffi.ZstdCompressor() with cctx.write_to(dest) as compressor: compressor.write(orig.getvalue()) uncompressed = io.BytesIO() dctx = zstd.ZstdDecompressor() with dctx.write_to(uncompressed) as decompressor: decompressor.write(dest.getvalue()) self.assertEqual(uncompressed.getvalue(), orig.getvalue())