mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 01:52:01 -08:00
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:
parent
ebb6e845bf
commit
0227596f90
@ -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()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
@ -37,7 +38,7 @@ func (t *XMPPTransport) Connect() (string, error) {
|
||||
}
|
||||
|
||||
t.readWriter = newStreamLogger(t.conn, t.logFile)
|
||||
t.decoder = xml.NewDecoder(t.readWriter)
|
||||
t.decoder = xml.NewDecoder(bufio.NewReaderSize(t.readWriter, maxPacketSize))
|
||||
t.decoder.CharsetReader = t.Config.CharsetReader
|
||||
return t.StartStream()
|
||||
}
|
||||
@ -90,7 +91,7 @@ func (t *XMPPTransport) StartTLS() error {
|
||||
|
||||
t.conn = tlsConn
|
||||
t.readWriter = newStreamLogger(tlsConn, t.logFile)
|
||||
t.decoder = xml.NewDecoder(t.readWriter)
|
||||
t.decoder = xml.NewDecoder(bufio.NewReaderSize(t.readWriter, maxPacketSize))
|
||||
t.decoder.CharsetReader = t.Config.CharsetReader
|
||||
|
||||
if !t.TLSConfig.InsecureSkipVerify {
|
||||
|
Loading…
Reference in New Issue
Block a user