Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify buffer size before reading #12

Closed
Nevon opened this issue Dec 15, 2017 · 1 comment
Closed

Verify buffer size before reading #12

Nevon opened this issue Dec 15, 2017 · 1 comment

Comments

@Nevon
Copy link
Collaborator

Nevon commented Dec 15, 2017

#11 was caused by attempting to read the offset and size from the buffer without checking that there were enough bytes in the buffer. The fix was to simply do that check first:

if (!decoder.canReadInt64()) {
throw new KafkaJSPartialMessageError(
`Tried to decode a partial message: There isn't enough bytes to read the offset`
)
}
const offset = decoder.readInt64().toString()

However, we don't want to have to do these checks manually everywhere we try to read from a buffer. We could check the buffer size in the decoder itself, but it doesn't have the knowledge about messages etc, so it would just be able to throw very generic errors.

The suggestion is to never use theDecoder directly, but rather create specific decoders for what we are trying to decode, for example MessageDecoder, which can call the primitive methods on the Decoder, catch the generic errors and re-throw more specific ones.

@Nevon
Copy link
Collaborator Author

Nevon commented Jan 17, 2019

This is probably not happening anytime soon. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants