-
Notifications
You must be signed in to change notification settings - Fork 128
PVA: harden handling of protocol sizes #3878
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,8 @@ | |
| public void decode(final PVATypeRegistry types, final ByteBuffer buffer) throws Exception | ||
| { | ||
| final int size = PVASize.decodeSize(buffer); | ||
| if (size < 0 || size > buffer.remaining()) | ||
| throw new Exception("Array size " + size + " with only " + buffer.remaining() + " bytes in buffer"); | ||
|
Check warning on line 118 in core/pva/src/main/java/org/epics/pva/data/PVAByteArray.java
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not throw this inside PVASize.decodeSize? Then you don't need to update every single type.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decoding the size doesn't fail. It parses the size just fine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, then a tiny method checkRemainingSize(min, max, remaining) So that the code isn't repeated and you don't repeat yourself unnecessarily. |
||
| final byte[] new_value = new byte[size]; | ||
| buffer.get(new_value); | ||
| value = new_value; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a unit test that checks this exception is raised.