fix(mp3): guard sub-frame tail in getAlignedSegmentSize to prevent over-read past availableBytes
This commit is contained in:
@@ -79,10 +79,14 @@ export class Mp3FormatDecoder implements IFormatDecoder {
|
||||
|
||||
if (info.blockAlign > 0) {
|
||||
// CBR: align to complete MP3 frames so each segment is independently decodable.
|
||||
// Guard: need at least one full frame; discard sub-frame tail rather than over-reading.
|
||||
if (availableBytes < info.blockAlign) return 0;
|
||||
|
||||
const minFrames = Math.ceil(minSize / info.blockAlign);
|
||||
const availableFrames = Math.floor(availableBytes / info.blockAlign);
|
||||
if (!streamComplete && availableFrames < minFrames) return 0;
|
||||
const requestedFrames = Math.floor(Math.min(requestedSize, availableBytes) / info.blockAlign);
|
||||
// Never exceed availableBytes (clamp via requestedFrames which is floor'd from availableBytes).
|
||||
return Math.max(streamComplete ? 1 : minFrames, requestedFrames) * info.blockAlign;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user