Fix bdecode busy-loop on truncated torrent payloads.
Malformed bencode could set pos.i to NaN and hang Jest forever; guard the decoder and align the no-url-list fixture with current qbt behavior.
This commit is contained in:
@@ -34,6 +34,17 @@ describe('extractWebseed', () => {
|
||||
expect(extractWebseed(Buffer.from('not a torrent'))).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for truncated dict (no busy-loop)', () => {
|
||||
// Previously: dict key "pieces" without value → bdecode infinite loop
|
||||
const truncated = Buffer.from(
|
||||
'd4:infod6:lengthi0e4:name4:teste12:piece lengthi524288e6:piecese',
|
||||
'utf8',
|
||||
);
|
||||
const t0 = Date.now();
|
||||
expect(extractWebseed(truncated)).toBeNull();
|
||||
expect(Date.now() - t0).toBeLessThan(100);
|
||||
});
|
||||
|
||||
it('returns null when url-list is missing', () => {
|
||||
// Bencode a dict without url-list
|
||||
const buf = makeTorrent({ name: 'f.mkv', size: 0, webseedUrl: 'http://x.com/s/a' });
|
||||
|
||||
Reference in New Issue
Block a user