From 48f8c577c0f3a0a83ce3557216894f6a59cf30cc Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Sat, 10 Feb 2024 20:13:17 +0600 Subject: [PATCH] Fixed a buffer overflow error when converting videos when the video is more than 2 hours long. --- src/handler/convertor.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/handler/convertor.go b/src/handler/convertor.go index db2f7e2..e878665 100644 --- a/src/handler/convertor.go +++ b/src/handler/convertor.go @@ -178,19 +178,30 @@ func (p Progress) Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error { progress := 0.0 go func() { - scannerErr := bufio.NewScanner(stdErr) - for scannerErr.Scan() { - errorText = scannerErr.Text() - } - if err := scannerErr.Err(); err != nil { - errorText = err.Error() + scannerErr := bufio.NewReader(stdErr) + for { + line, _, err := scannerErr.ReadLine() + if err != nil { + if err == io.EOF { + break + } + continue + } + data := strings.TrimSpace(string(line)) + errorText = data } }() - scannerOut := bufio.NewScanner(stdOut) - for scannerOut.Scan() { - data := scannerOut.Text() - + scannerOut := bufio.NewReader(stdOut) + for { + line, _, err := scannerOut.ReadLine() + if err != nil { + if err == io.EOF { + break + } + continue + } + data := strings.TrimSpace(string(line)) if strings.Contains(data, "progress=end") { p.progressbar.Value = p.totalDuration p.progressbar.Refresh()