[Bug 267032] diff(1) -U and -C with very large number of context may produce incorrect line indicator

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 15 Oct 2022 09:54:51 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267032

Daniel Tameling <tamelingdaniel@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tamelingdaniel@gmail.com

--- Comment #1 from Daniel Tameling <tamelingdaniel@gmail.com> ---
I had a look at this and there are two kinds of overflows that happen.

The first is for the line number. Here the code does something like

upd = MIN(len[1], context_vec_ptr->d + diff_context);

where the addition can overflow. The fix is to just use len[1] if that would
happen.

The second overflow happens when checking whether the current chuck overlaps
with the next one. This is why the command you posted has so much output; it
should just be one large chunk. The code of the check is

} else if (a > context_vec_ptr->b + (2 * diff_context) + 1 &&
           c > context_vec_ptr->d + (2 * diff_context) + 1) {

To fix this one should check if an overflow would happen and if that is the
case to not execute the body of the else if.

-- 
You are receiving this mail because:
You are the assignee for the bug.