diff -pruN 0.1.19+dfsg-5/debian/changelog 0.1.19+dfsg-5ubuntu1/debian/changelog
--- 0.1.19+dfsg-5/debian/changelog	2022-01-18 17:49:14.000000000 +0000
+++ 0.1.19+dfsg-5ubuntu1/debian/changelog	2022-08-01 17:03:43.000000000 +0000
@@ -1,3 +1,12 @@
+samtools-legacy (0.1.19+dfsg-5ubuntu1) kinetic; 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 <frank.heimes@canonical.com>  Mon, 01 Aug 2022 19:03:43 +0200
+
 samtools-legacy (0.1.19+dfsg-5) unstable; urgency=medium
 
   * Team upload.
diff -pruN 0.1.19+dfsg-5/debian/control 0.1.19+dfsg-5ubuntu1/debian/control
--- 0.1.19+dfsg-5/debian/control	2022-01-18 17:49:14.000000000 +0000
+++ 0.1.19+dfsg-5ubuntu1/debian/control	2022-08-01 17:03:43.000000000 +0000
@@ -1,5 +1,6 @@
 Source: samtools-legacy
-Maintainer: Debian Med Packaging Team <debian-med-packaging@lists.alioth.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Debian Med Packaging Team <debian-med-packaging@lists.alioth.debian.org>
 Uploaders: Charles Plessy <plessy@debian.org>
 Section: science
 Priority: optional
diff -pruN 0.1.19+dfsg-5/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch 0.1.19+dfsg-5ubuntu1/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch
--- 0.1.19+dfsg-5/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.1.19+dfsg-5ubuntu1/debian/patches/515f6df-Remove-compressBound-assertions-PR-1258.patch	2022-08-01 17:03:43.000000000 +0000
@@ -0,0 +1,100 @@
+From 515f6df8f7f7dab6c80d0e7aede6e60826ef5374 Mon Sep 17 00:00:00 2001
+From: James Bonfield <jkb@sanger.ac.uk>
+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, https://github.com/samtools/htslib/commit/515f6df
+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1961427
+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1983255
+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 -pruN 0.1.19+dfsg-5/debian/patches/series 0.1.19+dfsg-5ubuntu1/debian/patches/series
--- 0.1.19+dfsg-5/debian/patches/series	2022-01-18 17:49:14.000000000 +0000
+++ 0.1.19+dfsg-5ubuntu1/debian/patches/series	2022-08-01 17:03:43.000000000 +0000
@@ -3,3 +3,4 @@ fix_segfault_with_small_ref.patch
 fix_coverage_cap.patch
 hardening.patch
 gcc-11.patch
+515f6df-Remove-compressBound-assertions-PR-1258.patch
