Hacker News new | ask | show | jobs
by userbinator 4187 days ago
How does this happen? My guess is there is a loop that processes file contents in 8KB blocks, something like this:

    bytesRemaining = fileSize;
    while(...) {
        ...
        bytesRemaining -= 8192;
        if(bytesRemaining < 0)
            break;
        ...
    }
    bytesRemaining += 8192;
    ...
    // process remaining bytes

See the bug? :-)
4 comments

The power of the almighty equal sign
Very likely something like this or similar to this.
If this was the case then any multiple of 8KB should also cause the bug to happen, but according to OP only exactly 8KB causes the bug.
"and is caused by the presence of a file that's exactly 8,192 bytes (8KB) or a multiple thereof."
The article itself says that multiples do cause the bug.
Yes. The while statement can't take variable arguments. Also, ellipsis is not a standalone expression. Also, if "fileSize" is exactly 8192 then ellipsis will execute because "bytesRemaining" will equal zero. If your compiler actually compiles ellipsis and "fileSize" is exactly 8192, then something bad will probably happen. Either the undefined behavior of the compiled ellipses or the unexpected negative number will likely cause a crash.

Edit: I guess that was funnier in my head.