Skip to content

fix: harden AudioLoader against SIGSEGV from corrupt/malformed audio frames#1500

Open
xiaden wants to merge 1 commit into
MTG:masterfrom
xiaden:fix/audioloader-crash-hardening
Open

fix: harden AudioLoader against SIGSEGV from corrupt/malformed audio frames#1500
xiaden wants to merge 1 commit into
MTG:masterfrom
xiaden:fix/audioloader-crash-hardening

Conversation

@xiaden
Copy link
Copy Markdown

@xiaden xiaden commented Feb 19, 2026

This PR Adds defensive guards in both decodePacket() and flushPacket() to prevent segmentation faults when processing corrupted or malformed audio files:

  • Check for null frame data pointers before memcpy/swr_convert
  • Validate channel count matches expected layout (prevents swr misuse)
  • Sanity-check nb_samples to prevent integer overflow in buffer size calc
  • Skip frames that would overflow FFMPEG_BUFFER_SIZE instead of clamping
  • Remove redundant std::min() clamping that masked the overflow silently

All guards emit E_WARNING with diagnostic details (codec name, sample count, channel count) and skip the offending frame rather than crashing.

Behavior

  • Valid audio: No observable change (A/B tested in bulk ML tagging workload)
  • Partially corrupted audio: Frames may now be skipped instead of processed
  • Fully corrupted frames that previously triggered SIGSEGV: Now handled safely

Notes

  • This implementation opts to skip invalid frames rather than abort processing. If a different failure strategy is preferred, I’m happy to adapt.

  • The changes were implemented with AI assistance, and I’m not deeply familiar with all invariants in this codebase, so I’d appreciate careful review, particularly around buffer handling and swr assumptions.

…frames

Add defensive guards in both decodePacket() and flushPacket() to prevent
segmentation faults when processing corrupted or malformed audio files:

- Check for null frame data pointers before memcpy/swr_convert
- Validate channel count matches expected layout (prevents swr misuse)
- Sanity-check nb_samples to prevent integer overflow in buffer size calc
- Skip frames that would overflow FFMPEG_BUFFER_SIZE instead of clamping
- Remove redundant std::min() clamping that masked the overflow silently

All guards emit E_WARNING with diagnostic details (codec name, sample
count, channel count) and skip the offending frame rather than crashing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant