Closed aeqz closed 3 months ago
Thanks for your detailed issue (and test!). This definitely sounds like something that should be fixed. We don't version this project (it's only really used as a standalone application), so I'm not worried about changing the type of the arguments.
That's interesting. I happen to be using it as a Go package for reading and writing messages over MLLP. I'm glad to hear that the function signature change can be considered as a solution!
Fixed in 903a912c95ba1a33b62100b3c8a4486aa6b37b9c
Currently, the
ReadMsg
function from themllp
package takes anio.Reader
argument and wraps it into abufio.Reader
in order to read until the message end delimiter. When doing this, data beyond the end delimiter may have been read from the argument reader and be left in the created reader buffer, resulting in the remaining messages being dropped or truncated:The previous test succeeds if we wrap the argument beforehand, because
bufio.NewReader
returns the passed reader if it is already abufio.Reader
with enough size (preventingmllp.ReadMsg
from creating a new buffer):Apart from this simple example, I have also seen this happening in a more realistic situation when reading messages from
net.Conn
s accepted from a TCPnet.Listener
.Should
mllp.ReadMsg
take abufio.Reader
rather than creating one in order to prevent this issue? If that is not possible for some reason (I understand that it would be a breaking change), is this already documented somewhere to let the users of this package know how to safely use this function? (I failed to find it if that's the case!).