-
Notifications
You must be signed in to change notification settings - Fork 34
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
Provide way to limit array size for whole stream array read #44
Comments
I didn't provide way to limit size of array and imho it is a good idea to provide such one. |
I have improved JBBP and added JBBPArraySizeLimiter which can be provided for JBBPBitInputStream read array methods and for JBBPParser to limit whole stream array read, it will be published in 2.1.0 release |
Thanks a lot! (And sorry for the late reply, I've been on holiday.) With the changes you've made, it's also possible to limit the length of arrays defined via expressions (using JBBPParserExpressionArraySizeController), is that correct? To give you more context (as I'm not sure my question makes sense), in my case the script is user-defined, and I want to restrict what the user can do to protect my service (but maybe there's a lot more than array size I should worry about). |
if you want to check statically defined array sizes, you can do some trick with visitor of compiled block which I use to generate java classes from scripts JBBPParser parser = JBBPParser.prepare("byte[100] one; byte [1000000] two;");
CompiledBlockVisitor visitor = new CompiledBlockVisitor(0, parser.getCompiledBlock()){
@Override
public void visitPrimitiveField(int offsetInCompiledBlock, int primitiveType,
JBBPNamedFieldInfo nullableNameFieldInfo,
JBBPByteOrder byteOrder,
boolean readWholeStreamAsArray,
boolean altFieldType,
JBBPIntegerValueEvaluator nullableArraySize) {
if (!readWholeStreamAsArray
&& nullableArraySize != null
&& nullableArraySize.getClass().getSimpleName().equals("IntConstValueEvaluator")) {
int size = nullableArraySize.eval(null, offsetInCompiledBlock, null, null);
if (size > 10000) {
throw new IllegalArgumentException("Too big array: " + nullableNameFieldInfo);
}
}
}
};
visitor.visit(); in the code above the exception will be thrown for too big static size of array, keep in mind that users can write something |
Thanks again for your help. (And that's noted for arrays of structures, I'll definitely check that too). |
I have made minor refactoring and added util method |
Thanks, it's very helpful! |
so, it looks like that since 3.0.0 version I have provided ways to detect too long arrays for calculated by expressions and static variants |
Thanks for letting me know! |
Hello
I'm trying to limit the length of arrays created by JBBP.
I was able to do it for JBBP types that way:
But I couldn't find a way for arrays of structures and arrays without a defined size (
[_]
).Do you see a way to do that? Otherwise is a change possible?
(I use the latest version.)
Thanks for your help.
The text was updated successfully, but these errors were encountered: