[Bug 280371] diff(1) attempts to allocate ~10^20 bytes while comparing 32GB text files

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 19 Jul 2024 15:53:21 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280371

            Bug ID: 280371
           Summary: diff(1) attempts to allocate ~10^20 bytes while
                    comparing 32GB text files
           Product: Base System
           Version: 14.1-STABLE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: yuri@freebsd.org

I tried to compare 2 large files:
> $ diff  broadinstitute-gatk-4.6.0.0_GH0.tar.good.hex broadinstitute-gatk-4.6.0.0_GH0.tar.bad.hex | more
> diff: xreallocarray: allocating 18446744073509292634 * 12 bytes: Cannot allocate memory

File sizes:
> $ ls -l broadinstitute-gatk-4.6.0.0_GH0.tar.good.hex broadinstitute-gatk-4.6.0.0_GH0.tar.bad.hex
> -rw-r--r--  1 yuri users 32676484755 Jul 18 21:07 broadinstitute-gatk-4.6.0.0_GH0.tar.bad.hex
> -rw-r--r--  1 yuri users 32676397537 Jul 18 20:06 broadinstitute-gatk-4.6.0.0_GH0.tar.good.hex

These files have some differences in the middle.

The failure is most likely due to an overflow.

diff(1) should be able to compare 32GB files without the need to allocate much
more memory than file sizes.

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