diff -Nru samtools-legacy-0.1.19/debian/changelog samtools-legacy-0.1.19/debian/changelog --- samtools-legacy-0.1.19/debian/changelog 2018-07-31 09:50:13.000000000 +0200 +++ samtools-legacy-0.1.19/debian/changelog 2022-08-08 13:28:37.000000000 +0200 @@ -1,3 +1,12 @@ +samtools-legacy (0.1.19-4ubuntu0.1) focal; urgency=medium + + * Add backport of upstream commit 515f6df as + d/p/515f6df-Remove-compressBound-assertions-PR-1258.patch + in support of fixing 'zlib: compressBound() returns an incorrect result + on z15'. (LP: #1983255) + + -- Frank Heimes Mon, 08 Aug 2022 13:28:37 +0200 + samtools-legacy (0.1.19-4) unstable; urgency=medium * Team upload. diff -Nru samtools-legacy-0.1.19/debian/control samtools-legacy-0.1.19/debian/control --- samtools-legacy-0.1.19/debian/control 2018-07-31 09:50:13.000000000 +0200 +++ samtools-legacy-0.1.19/debian/control 2022-08-08 13:28:37.000000000 +0200 @@ -1,5 +1,6 @@ Source: samtools-legacy -Maintainer: Debian Med Packaging Team +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Debian Med Packaging Team Uploaders: Charles Plessy Section: science Priority: optional diff -Nru samtools-legacy-0.1.19/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch samtools-legacy-0.1.19/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch --- samtools-legacy-0.1.19/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch 1970-01-01 01:00:00.000000000 +0100 +++ samtools-legacy-0.1.19/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch 2022-08-08 13:27:10.000000000 +0200 @@ -0,0 +1,99 @@ +From 515f6df8f7f7dab6c80d0e7aede6e60826ef5374 Mon Sep 17 00:00:00 2001 +From: James Bonfield +Date: Wed, 7 Apr 2021 16:39:59 +0100 +Subject: [PATCH] Remove compressBound assertions. (PR #1258) + +These trip on with zlib-ng as the worse case expansion is 9-bits per +byte (at level 1 only). The test is done on opening a file, which +seems strange. + +We could do the check on opening for write only, but it seems more +productive to error only when we actually can't fit the data rather +than just incase it may if given truely random input. Our real data +doesn't seem to trigger this. + +Random data with zlib-ng can cause data expansion beyond 64k. However +bgzf_compress already has code to handle uncompressed blocks, so we +just fall back to that (thanks to John Marshall for the idea). + +Fixes #1257 + +Backported to fit the outdated version of bgzf.c that is used +in package samtools-legacy-0.1.19+dfsg. + +Origin: upstream/backport, https://github.com/samtools/htslib.git515f6df +Bug-Ubuntu: https://bugs.launchpad.net/bugs/1961427 +Last-Update: 2022-05-10 + +--- + bgzf.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +--- a/bgzf.c ++++ b/bgzf.c +@@ -139,7 +139,6 @@ + BGZF *bgzf_open(const char *path, const char *mode) + { + BGZF *fp = 0; +- assert(compressBound(BGZF_BLOCK_SIZE) < BGZF_MAX_BLOCK_SIZE); + if (strchr(mode, 'r') || strchr(mode, 'R')) { + _bgzf_file_t fpr; + if ((fpr = _bgzf_open(path, "r")) == 0) return 0; +@@ -157,7 +156,6 @@ + BGZF *bgzf_dopen(int fd, const char *mode) + { + BGZF *fp = 0; +- assert(compressBound(BGZF_BLOCK_SIZE) < BGZF_MAX_BLOCK_SIZE); + if (strchr(mode, 'r') || strchr(mode, 'R')) { + _bgzf_file_t fpr; + if ((fpr = _bgzf_dopen(fd, "r")) == 0) return 0; +@@ -178,16 +176,39 @@ + z_stream zs; + uint8_t *dst = (uint8_t*)_dst; + +- // compress the body +- zs.zalloc = NULL; zs.zfree = NULL; +- zs.next_in = src; +- zs.avail_in = slen; +- zs.next_out = dst + BLOCK_HEADER_LENGTH; +- zs.avail_out = *dlen - BLOCK_HEADER_LENGTH - BLOCK_FOOTER_LENGTH; +- if (deflateInit2(&zs, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) return -1; // -15 to disable zlib header/footer +- if (deflate(&zs, Z_FINISH) != Z_STREAM_END) return -1; +- if (deflateEnd(&zs) != Z_OK) return -1; +- *dlen = zs.total_out + BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH; ++ if (level == 0) { ++ uncomp: ++ // Uncompressed data ++ if (*dlen < slen+5 + BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH) return -1; ++ dst[BLOCK_HEADER_LENGTH] = 1; // BFINAL=1, BTYPE=00; see RFC1951 ++ memcpy(dst + BLOCK_HEADER_LENGTH+5, src, slen); ++ *dlen = slen+5 + BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH; ++ } else { ++ // compress the body ++ zs.zalloc = NULL; zs.zfree = NULL; ++ zs.next_in = src; ++ zs.avail_in = slen; ++ zs.next_out = dst + BLOCK_HEADER_LENGTH; ++ zs.avail_out = *dlen - BLOCK_HEADER_LENGTH - BLOCK_FOOTER_LENGTH; ++ int ret = deflateInit2(&zs, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); // -15 to disable zlib header/footer ++ if (ret != Z_OK) return -1; ++ if ((ret = deflate(&zs, Z_FINISH)) != Z_STREAM_END) { ++ if (ret == Z_OK && zs.avail_out == 0) { ++ deflateEnd(&zs); ++ goto uncomp; ++ } ++ return -1; ++ } ++ // If we used up the entire output buffer, then we either ran out of ++ // room or we *just* fitted, but either way we may as well store ++ // uncompressed for faster decode. ++ if (zs.avail_out == 0) { ++ deflateEnd(&zs); ++ goto uncomp; ++ } ++ if (deflateEnd(&zs) != Z_OK) return -1; ++ *dlen = zs.total_out + BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH; ++ } + // write the header + memcpy(dst, g_magic, BLOCK_HEADER_LENGTH); // the last two bytes are a place holder for the length of the block + packInt16(&dst[16], *dlen - 1); // write the compressed length; -1 to fit 2 bytes diff -Nru samtools-legacy-0.1.19/debian/patches/series samtools-legacy-0.1.19/debian/patches/series --- samtools-legacy-0.1.19/debian/patches/series 2018-07-31 09:50:13.000000000 +0200 +++ samtools-legacy-0.1.19/debian/patches/series 2022-08-08 13:27:32.000000000 +0200 @@ -1,3 +1,4 @@ fix_example_makefile.patch fix_segfault_with_small_ref.patch fix_coverage_cap.patch +515f6df-Remove-compressBound-assertions-PR-1258.patch