Increase size of XML decoder internal buffers

Since a transport (and a streamlogger) does not implement io.ByteReader
xml.Decoder wraps it using `bufio.NewReader(transport)` so it can easily read
bytes one at a time. This has the unfortuante effect of resulting in a panic if
we try to parse a stanza that is larger than the default buffer size of 4096
bytes.

To fix this we wrap the transport using `bufio.NewReaderSize()` with a much
larger buffer size.
This commit is contained in:
Wichert Akkerman
2019-11-01 21:57:38 +01:00
committed by Mickaël Rémond
parent ebb6e845bf
commit 0227596f90
2 changed files with 5 additions and 3 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
package xmpp
import (
"bufio"
"context"
"encoding/xml"
"errors"
@@ -57,7 +58,7 @@ func (t *WebsocketTransport) Connect() (string, error) {
t.wsConn = wsConn
t.startReader()
t.decoder = xml.NewDecoder(t)
t.decoder = xml.NewDecoder(bufio.NewReaderSize(t, maxPacketSize))
t.decoder.CharsetReader = t.Config.CharsetReader
return t.StartStream()