Article View: linux.debian.bugs.dist
Article #6670Bug#1155740: apt: rred: merging patches with a line of 512 KiB or more fails or gives a wrong result
From: Ansgar 🙀
Date: Sun, 29 Nov 2026 09:00
Date: Sun, 29 Nov 2026 09:00
134 lines
5888 bytes
5888 bytes
Package: apt
Version: 3.3.6
Control: found -1 3.0.4
Hi,
I added error checking to dak and pdiff generation started to fail as
rred was returning an error. A LLM found a larger problem where rred
can also generate wrong results when long lines are present, see the
analysis below.
For Debian's archive this affects at least Contents-source where we
will now drop most pdiffs until the rred bug is fixed (or another
workaround is implemented). So fixing this in stable might be helpful.
Ansgar
---
When rred merges ed-style patches, either into a merged patch
("rred patch-1 patch-2 > merged") or while applying them
("rred -f patch-1 patch-2 < input > output"), a line of 512 KiB
(524288 bytes including the newline) or more added by an earlier patch
breaks the merge when a later patch changes the file:
- rred fails with exit status 2 and
E: No line left in add_len data to skip (1)
E: Parsing patchfile v1-v2.ed failed: Data couldn't be added for command (1)
- or rred exits with status 0, but the merged patch and the output of
"rred -f" are wrong.
Applying the same patches one after the other works, and lines of
524287 bytes or less are not affected.
dak uses rred to merge the pdiffs on ftp-master. main/Contents-source
in unstable and testing has lines of up to about 670 KB (for example
".pc/.quilt_patches", followed by the list of all source packages that
contain it), so merging its pdiffs failed. The same code is used when
apt merges pdiffs itself, for repositories that do not set
"X-Patch-Precedence: merged".
The script below reproduces both cases. v0-v1.ed replaces line 2 with
a line of 600000 bytes. v1-v2.ed replaces that line again, and merging
the two fails. v1-v3.ed replaces line 5 instead; the merged patch
should be
5c
E
.
2c
xxx...
.
but rred writes "4c" instead of "5c", so the merged patch changes line 4
instead of line 5.
---- rred-long-lines.sh ----
#!/bin/sh
# rred: merging patches with a line of 512 KiB or more fails or gives a
# wrong result
set -u
RRED=${RRED:-/usr/lib/apt/methods/rred}
dir=$(mktemp -d)
cd "$dir" || exit 1
long_line() { head -c 600000 /dev/zero | tr '\0' x; echo; }
printf 'a\nb\nc\nd\ne\n' > v0
{ echo a; long_line; printf 'c\nd\ne\n'; } > v1 # v0 with b replaced by a long line
printf 'a\nb\nc\nd\ne\n' > v2 # v1 with the long line replaced by b
{ echo a; long_line; printf 'c\nd\nE\n'; } > v3 # v1 with e replaced by E
diff --ed v0 v1 > v0-v1.ed
diff --ed v1 v2 > v1-v2.ed
diff --ed v1 v3 > v1-v3.ed
echo "== Applying the patches one after the other works:"
"$RRED" -f v0-v1.ed < v0 | "$RRED" -f v1-v2.ed | cmp - v2 && echo "v0 -> v2: ok"
"$RRED" -f v0-v1.ed < v0 | "$RRED" -f v1-v3.ed | cmp - v3 && echo "v0 -> v3: ok"
echo "== Merging v0-v1.ed and v1-v2.ed fails:"
"$RRED" v0-v1.ed v1-v2.ed > v0-v2.ed
echo "exit status $?"
echo "== Merging v0-v1.ed and v1-v3.ed succeeds, but the merged patch is wrong:"
"$RRED" v0-v1.ed v1-v3.ed > v0-v3.ed
echo "exit status $?"
echo "merged patch (lines cut to 20 characters):"
cut -c 1-20 v0-v3.ed
"$RRED" -f v0-v3.ed < v0 | cmp - v3
echo "== Applying both patches in one go gives the same wrong result:"
"$RRED" -f v0-v1.ed v1-v3.ed < v0 > v3.out
echo "exit status $?"
cmp v3.out v3
---- end of rred-long-lines.sh ----
Output with apt 3.3.6:
== Applying the patches one after the other works:
v0 -> v2: ok
v0 -> v3: ok
== Merging v0-v1.ed and v1-v2.ed fails:
E: No line left in add_len data to skip (1)
E: Parsing patchfile v1-v2.ed failed: Data couldn't be added for command (1)
exit status 2
== Merging v0-v1.ed and v1-v3.ed succeeds, but the merged patch is wrong:
exit status 0
merged patch (lines cut to 20 characters):
4c
E
.
2c
xxxxxxxxxxxxxxxxxxxx
.
- v3 differ: byte 600006, line 4
== Applying both patches in one go gives the same wrong result:
exit status 0
v3.out v3 differ: byte 600006, line 4
read_diff() in methods/rred.cc reads the patch with FileFd::ReadLine()
into a buffer of APT_MEMBLOCK_SIZE (512 KiB) bytes and counts every
chunk it gets as one line, also when the chunk does not end in a
newline. The main branch has the same code.
Technical Details
Message-ID:
<O4IVj-eQlN-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!news-ams.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Ansgar 🙀 <ansgar@debian.org> Newsgroups: linux.debian.bugs.dist Subject: Bug#1155740: apt: rred: merging patches with a line of 512 KiB or more fails or gives a wrong result Date: Sun, 29 Nov 2026 10:00:01 +0100 Message-ID: <O4IVj-eQlN-1@gated-at.bofh.it> X-Original-To: submit@bugs.debian.org X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org Sun Nov 29 08:57:08 2026 Old-Return-Path: <debbugs@buxtehude.debian.org> X-Spam-Flag: NO X-Spam-Score: -1.7 Reply-To: Ansgar 🙀 <ansgar@debian.org>, 1155740@bugs.debian.org Resent-To: debian-bugs-dist@lists.debian.org Resent-Cc: deity@lists.debian.org X-Debian-Pr-Message: report 1155740 X-Debian-Pr-Package: apt X-Debian-Pr-Source: apt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.62.1-4 MIME-Version: 1.0 X-Debian-Message: from BTS X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2005785 List-ID: <debian-bugs-dist.lists.debian.org> List-URL: <https://lists.debian.org/debian-bugs-dist/> Approved: robomod@news.nic.it Lines: 134 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Sun, 29 Nov 2026 09:54:19 +0100 X-Original-Message-ID: <833c4206e5a439e16be37d39856f33fc668f4661.camel@debian.org>