What are some taint sources in this binary?
In bzip2, the primary taint‐sources you’ll want to seed your analysis with are any place data enters the program from the outside. In this binary those include:
-
Command‐line arguments
– Theargv[]strings passed intomain. -
Environment variables
– Calls togetenv. -
File‐based input
– fopen/open (e.g.fopen64,open64,open)
– fdopen/fileno
– Raw reads:fread,fgetc/ungetc
– BZ2 library reads:BZ2_bzReadOpen,BZ2_bzRead,BZ2_bzReadGetUnused -
Standard‐input
– If you run “bzip2 –c” without filenames, stdin is consumed via the samefread/fgetcpaths.
Any data coming in through one of those APIs should be marked tainted before it’s fed into the decompressor or passed down into string routines (strncpy, strstr, etc.) where you’ll look for overflows or logic bugs.
Can you find any potential CWEs from those sources? Only consider the sources that, to your best knowledge, are exploitable.
Here are the only realistic exploitable weakness classes (CWEs) I can see, given the taint‐sources we identified and how they’re used in this build of bzip2:
-
CWE-400: Uncontrolled Resource Consumption
• Any attacker-controlled bzip2 stream (via stdin or file-input) can expand to arbitrary size in memory or disk I/O, so you can trivially DoS the process (and even the host if swap or disk fills). -
CWE-22: Path Traversal
• Filenames come straight from argv[] (e.g. “../foo”) and then get passed to remove()/open()/fdopen()/fchmod()/fchown(), so you can delete or overwrite files outside your working directory if you control the name. -
CWE-367: Time-of-Check Time-of-Use Race Condition
• bzip2 opens a file by name and later unlinks/removes it; an attacker who races in can swap in a symlink/device/other file between the open and the remove to escalate privileges or delete the wrong target. -
(Less severe) CWE-252: Unchecked Return Values
• A handful of calls (getenv, fread, malloc, fopen64, etc.) aren’t always checked for error/null before use—this can lead to crashes, but not straight RCE.
I didn’t spot any classic buffer-overflows (CWE-119) in this build—every strcpy/memcpy is rewritten as the “chk” variant or bounded by explicit length checks—so overflow attacks look non-viable here.
What causes CWE-400?
CWE-400 (Uncontrolled Resource Consumption) in bzip2 boils down to its unbounded decompression loop. In particular:
• In FUN_00105990 (the “test”/decompress entry), after opening your input it calls
FUN_00104220(pFVar4)
• FUN_00104220 repeatedly reads compressed blocks (via BZ2 routines or internal bit-stream parsing), allocates buffers based on the block headers, and writes out every byte of the decompressed stream—without ever checking “Have we expanded more than X bytes?” or enforcing any cap on total memory or disk I/O.
An attacker can feed a very small (or CPU-cheap) compressed file that explodes into gigabytes of output (and corresponding malloc/fwrite calls), easily exhausting RAM, disk space or I/O bandwidth and bringing the process (or host) to its knees. That unbounded inflate-and-write behavior is exactly what triggers CWE-400 here.
