Skip to content

MEDIUM: audio download in fingerprint.py has no byte-count cap — pirate server can stream unbounded bytes #78

Description

@walidboulanouar

Problem

apps/scanner/fingerprint.py lines 227–250:

async for chunk in resp.aiter_bytes(chunk_size=65536):
    handle.write(chunk)

The download has a 60-second timeout but no byte-count limit. A piracy server returning HTTP 200 with an infinite body will fill disk until the OS kills the process or the timeout fires. At 10 Mbps for 60 seconds that is ~75 MB per fingerprint job.

Also: subprocess.run for fpcalc and ffmpeg at lines 188–197 has no timeout= parameter — a maliciously crafted audio file or codec bug can hang a thread-pool slot indefinitely.

Fix

MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024
total = 0
async for chunk in resp.aiter_bytes(chunk_size=65536):
    total += len(chunk)
    if total > MAX_DOWNLOAD_BYTES:
        raise FingerprintError(f'download exceeded {MAX_DOWNLOAD_BYTES} bytes')
    handle.write(chunk)

And for subprocess: subprocess.run(cmd, timeout=CLIP_SECONDS + 30, ...) with except subprocess.TimeoutExpired: raise FingerprintError('ffmpeg timed out').

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions