#2400·aria2

attacker-controlled piece_length=0 in .torrent/magnet BitTorrent info dict causes SIGFPE divide-by-zero crash

Author: router0mailCreated Sep 18, 2026Updated Sep 18, 2026

Summary

processRootDictionary reads the attacker-controlled piece length bencode integer and only checks it is not negative -- never that it is nonzero -- before using it as a divisor in a piece-count computation. A malicious .torrent file, or a magnet link resolved against an attacker-controlled peer/tracker serving a crafted BEP9 ut_metadata info dict, with piece length set to 0 crashes the aria2 process with SIGFPE before any download activity starts.

Root cause

src/bittorrent_helper.cc:465-469, ~498:

cpp
if (pieceLengthData->i() < 0) {
  throw DL_ABORT_EX(...);
}
// no check that pieceLengthData->i() != 0

size_t pieceLength = pieceLengthData->i();
...
(ctx->getTotalLength() + pieceLength - 1) / pieceLength   // divide by attacker-supplied 0

DownloadContext::getNumPieces() (src/DownloadContext.cc:206-216) already explicitly checks pieceLength_ == 0 before dividing -- processRootDictionary inlines a duplicate of the same formula but never got the same guard. The parallel Metalink pieces@length path funnels through the already-guarded getNumPieces() and is safe.

Proof of concept

Crafted bencode info dict:

d4:name1:x12:piece lengthi0e6:pieces20:AAAAAAAAAAAAAAAAAAAA6:lengthi100ee

piece length = 0, valid pieces (one 20-byte SHA1 placeholder), valid length. Loading via aria2c malicious.torrent, or a magnet URI resolved against an attacker-run peer/tracker returning this as the BEP9 ut_metadata info dict, reaches processRootDictionary and divides by 0 -- SIGFPE, process crash. Not run through an actual build/fuzzer in this pass -- recommend wrapping bittorrent::loadFromMemory() with single-field-mutated bencode dicts as the next verification step.

Impact

Remote, unauthenticated DoS: any .torrent file or magnet link (resolved against an attacker-controlled peer) can crash a running aria2 process with zero preconditions beyond opening/adding it. No memory corruption, no code execution.

Suggested fix

Add pieceLengthData->i() == 0 to the existing negative-value check at bittorrent_helper.cc:465-469, throwing the same DL_ABORT_EX as the negative case.


This report was produced with AI assistance (Claude, Anthropic) via source-code trace, cross-referencing the codebase's own already-correctly-guarded parallel implementation of the same formula. Not live-fired/fuzzed against a real build in this pass.