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

Repeated, long SD causes BufferOverflow #21

Open
StrongestNumber9 opened this issue Aug 3, 2023 · 4 comments
Open

Repeated, long SD causes BufferOverflow #21

StrongestNumber9 opened this issue Aug 3, 2023 · 4 comments

Comments

@StrongestNumber9
Copy link
Contributor

StrongestNumber9 commented Aug 3, 2023

Something like

        StringBuilder x = new StringBuilder();
        String key = new String(new char[32]).replace("\0", "X");
        String value = new String(new char[32]).replace("\0", "X");
        sdSubscription.subscribeElement("id@0", key);
        for(int i=0; i<=1000; i++) {
            x.append("[id@0 ").append(key).append("=\"").append(value).append("\"]");
        }
        String input = x+"[id@0 keyHere=\"valueThere\"] ";

causes

java.nio.BufferOverflowException
        at java.base/java.nio.Buffer.nextPutIndex(Buffer.java:722)
        at java.base/java.nio.DirectByteBuffer.put(DirectByteBuffer.java:352)
        at com.teragrep.rlo_06.StructuredData.accept(StructuredData.java:163)
        at com.teragrep.rlo_06.StructuredDataTest.longSD(StructuredDataTest.java:64)

Stacktrace truncated as it is from junit

@StrongestNumber9
Copy link
Contributor Author

Maybe move

short sdElemVal_max_left = 8 * 1024;

to

}
while (b == 91) { // '[' sd exists

At least that fixed the crashing, but never threw out of the loop or any exceptions

@StrongestNumber9
Copy link
Contributor Author

      STRUCTURED-DATA = NILVALUE / 1*SD-ELEMENT
      SD-ELEMENT      = "[" SD-ID *(SP SD-PARAM) "]"
      SD-PARAM        = PARAM-NAME "=" %d34 PARAM-VALUE %d34
      SD-ID           = SD-NAME
      PARAM-NAME      = SD-NAME
      PARAM-VALUE     = UTF-8-STRING ; characters '"', '\' and
                                     ; ']' MUST be escaped.
      SD-NAME         = 1*32PRINTUSASCII
                        ; except '=', SP, ']', %d34 (")

As far as I can tell, nothing prevents me from having a lot of key=value combinations, or that how long the values are. Currently seems to be limited to 8K total even though 256K sized messages are supported in many places

@StrongestNumber9
Copy link
Contributor Author

StrongestNumber9 commented Aug 3, 2023

mapHashMap.get(sdIdByteBuffer).put(sdElemByteBuffer, ByteBuffer.allocateDirect(8*1024));

hashMap.put(cloneByteBuffer(sdElementIterator), ByteBuffer.allocateDirect(8 * 1024));

Seems to contain hardcoded 8K limit as well

@StrongestNumber9
Copy link
Contributor Author

StrongestNumber9 commented Aug 3, 2023

My test that crashed on 8*1024 is now working when I changed it to 256*1024, that limit might be the reason.

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

No branches or pull requests

1 participant