Fix out of range end get (#1495)

This commit is contained in:
Zoe Roux 2026-05-10 18:05:31 +02:00 committed by GitHub
commit 7f9ccf9ffd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -196,6 +196,9 @@ func (ts *Stream) run(ctx context.Context, start int32) error {
end_padding := int32(1)
if end == length {
end_padding = 0
} else if copy_audio {
// Copy-audio runs keep one extra overlap segment because we drop it
end_padding += 1
}
segments := ts.keyframes.Slice(start_segment+1, end+end_padding)
if len(segments) == 0 {
@ -344,7 +347,7 @@ func (ts *Stream) run(ctx context.Context, start int32) error {
cmd.Process.Signal(os.Interrupt)
slog.InfoContext(ctx, "killing ffmpeg because segment already ready", "segment", segment, "encoderId", encoder_id)
should_stop = true
} else if copy_audio && end < length && segment == end-1 {
} else if copy_audio && end < length-1 && segment == end {
// Extra overlap segment for copied audio.
// Delete the file immediately and stop without closing
// the channel, so a real producer can close it later.

View File

@ -178,8 +178,8 @@ func listHeadRanges(file *FileStream, stream *Stream, isVideo bool, index uint32
end := stream.file.Info.Duration
length, _ := stream.keyframes.Length()
if head.end <= length {
end = stream.keyframes.Get(head.end)
if head.end-1 < length {
end = stream.keyframes.Get(head.end - 1)
}
ret = append(ret, HeadRange{
@ -204,7 +204,7 @@ func listHeadRanges(file *FileStream, stream *Stream, isVideo bool, index uint32
ret = append(ret, HeadRange{
Start: stream.keyframes.Get(start),
End: stream.keyframes.Get(end),
End: stream.keyframes.Get(end - 1),
StartHead: start,
EndHead: end,
IsRunning: false,