Comments (6)
From [email protected] on November 14, 2014 16:47:41
Actually it looks like it mishandles short messages because of confusion wrt lenBuf, or something. Still debugging.
from protobuf.
From [email protected] on November 14, 2014 17:06:03
So my theory is that messages shorter than len(lenBuf) are mishandled, in two ways:
- EOF is triggered one message too early
- it looks like the unconditional read of len(lenBuf)=10 bytes causes bytes to be lost
Consider two messages, 5 bytes in length, so taking each 1+5 bytes on the wire. The first read will slurp 10 bytes into lenBuf, and while it shuffles the extra from lenBuf to buf, nothing preserves those bytes between ReadMsg calls. Hence, the second message starts decoding a uvarint at byte #11, which is in the middle of the message.
Here's a version using bufio that Works For Me(tm):
func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser {
vr := &varintReader{
r: bufio.NewReader(r),
maxSize: maxSize,
}
if closer, ok := r.(io.Closer); ok {
vr.closer = closer
}
return vr
}
type varintReader struct {
r *bufio.Reader
buf []byte
maxSize int
closer io.Closer
}
func (this *varintReader) ReadMsg(msg proto.Message) error {
length64, err := binary.ReadUvarint(this.r)
if err != nil {
return err
}
msgLen := int(length64)
if len(this.buf) < msgLen {
this.buf = make([]byte, msgLen)
}
if _, err := io.ReadFull(this.r, this.buf[:msgLen]); err != nil {
return err
}
return proto.Unmarshal(this.buf[:msgLen], msg)
}
func (this *varintReader) Close() error {
if this.closer != nil {
return this.closer.Close()
}
return nil
}
from protobuf.
From awalterschulze on November 20, 2014 23:13:07
Yes seems like I really overcomplicated this reader.
Good catch.
Status: Accepted
Labels: -Priority-Medium Priority-Critical
from protobuf.
From awalterschulze on November 20, 2014 23:49:26
Do you want any copyright for this code?
from protobuf.
From [email protected] on November 21, 2014 09:20:27
It's trivial enough that it doesn't matter. Thanks for your work on gogoprotobuf!
from protobuf.
From awalterschulze on November 25, 2014 07:57:38
Thank you for reporting the issue
Status: Fixed
from protobuf.
Related Issues (20)
- panic: protobuf tag not enough fields in Empty.state HOT 1
- Enum filling with negative numbers will report an error, is it the Enum that does not support negative numbers?
- License question
- protoreflect
- Vulnerability?
- Panic: invalid Go type HOT 3
- github.com/gogo/protobuf is not installed
- Improper Input Validation in GoGo Protobuf HOT 1
- string time and duration
- oom
- Panic: reflect: Elem of invalid type HOT 1
- How to customize the name of an enumeration value, using the extension `enumvalue_customname ` seems unable to complete.
- m argument not work
- Call command.Generate(req *plugin.CodeGeneratorRequest) twice could cause bug.
- BUG: protoc-gen-gogofast not generate trailing comments
- How to generate parameter "description" in message of proto3 HOT 1
- proto: protect field access with lock to avoid possible data race
- proto: protect field access with lock to avoid possible data race
- Release v1.3.3 - Please please please create it pointing to v1.3.2
- Unsafe type assertion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf.