Subject: bug#9780: sort -u throws out non-duplicates

From: Rasmus Borup Hansen <[email-masked]>
Date: Tue, 14 Aug 2012 10:17:21 +0200

I came across this bug and have written a small shell script (below) that reproduces it on recent Linux distributions. It also reproduces the error using the latest coreutils compiled from sources.

Best regards,

Rasmus

#!/bin/sh

# Generate a file consisting only of 24 long sequences of lines with
# numbers from 0 to 23. This is actually a file that strongly
# resembles one we came upon during our work.

(
    for i in `seq 1 18624` ; do echo 18; done
    for i in `seq 1 69001` ; do echo 10; done
    for i in `seq 1 37950` ; do echo 20; done
    for i in `seq 1 124026` ; do echo 2; done
    for i in `seq 1 52202` ; do echo 15; done
    for i in `seq 1 3660` ; do echo 0; done
    for i in `seq 1 71627` ; do echo 5; done
    for i in `seq 1 69989` ; do echo 19; done
    for i in `seq 1 65192` ; do echo 9; done
    for i in `seq 1 51058` ; do echo 16; done
    for i in `seq 1 26810` ; do echo 13; done
    for i in `seq 1 56387` ; do echo 23; done
    for i in `seq 1 77273` ; do echo 7; done
    for i in `seq 1 159425` ; do echo 1; done
    for i in `seq 1 36851` ; do echo 22; done
    for i in `seq 1 102583` ; do echo 12; done
    for i in `seq 1 75429` ; do echo 17; done
    for i in `seq 1 82322` ; do echo 6; done
    for i in `seq 1 101135` ; do echo 3; done
    for i in `seq 1 63726` ; do echo 4; done
    for i in `seq 1 57302` ; do echo 14; done
    for i in `seq 1 57770` ; do echo 8; done
    for i in `seq 1 18032` ; do echo 21; done
    for i in `seq 1 101938` ; do echo 11; done
) > inputfile

# There should be 24 unique lines in inputfile no matter what the -S
# parameter to sort is.

for SIZE in `seq 128 140` ; do
    sort -S $SIZE -u inputfile | wc -l
done

# Ubuntu 12.04     OpenSuSE 11.4    SLES 10 SP1      Gentoo
# coreutils 8.12   coreutils 8.9    coreutils 5.93   coreutils 8.14
# 23               24               24               24
# 24               24               24               24
# 24               24               24               23
# 23               23               24               24
# 24               21               24               22
# 24               24               24               23
# 22               23               24               23
# 24               23               24               23
# 22               24               24               23
# 24               24               24               24
# 24               24               24               24
# 24               24               24               22
# 24               24               24               23