about summary refs log tree commit diff stats
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-07-28 09:59:03 +0200
committerReto Brunner <reto@labrat.space>2020-07-30 19:35:59 +0200
commit1bab1754f095a5c0537fc639d0214f6efbb340a2 (patch)
tree2c062c9f4b4641a59e3f4f3ff3317f636bfd49cf /widgets/msgviewer.go
parent01885e24487d171435501767f91ef06a305bc09d (diff)
downloadaerc-1bab1754f095a5c0537fc639d0214f6efbb340a2.tar.gz
msgviewer: set max line length to 1 GB
some people send around huge html without any newline in between.
This did overflow the default 64KB buffer of bufio.Scanner.
If something can't fit in a GB there's no hope left

Also, ignoring errors is bad mkey
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index d6085bf..107ff59 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"os"
 	"os/exec"
 	"regexp"
 	"strings"
@@ -641,11 +642,18 @@ func (pv *PartViewer) copyFilterOutToPager() {
 
 func (pv *PartViewer) copySourceToSinkStripAnsi() {
 	scanner := bufio.NewScanner(pv.source)
+	// some people send around huge html without any newline in between
+	// this did overflow the default 64KB buffer of bufio.Scanner.
+	// If something can't fit in a GB there's no hope left
+	scanner.Buffer(nil, 1024*1024*1024)
 	for scanner.Scan() {
 		text := scanner.Text()
 		text = ansi.ReplaceAllString(text, "")
 		io.WriteString(pv.sink, text+"\n")
 	}
+	if err := scanner.Err(); err != nil {
+		fmt.Fprintf(os.Stderr, "failed to read line: %v\n", err)
+	}
 }
 
 func (pv *PartViewer) Invalidate() {