assertArrayLength throws exception in multi-thread
sky4star opened this issue · 5 comments
Hi @raydac ,
First of all, thanks for such a brilliant parser, it is very helpful! I am using it to parse TCP packets in Spark streaming.
Currently, i notice JBBP throws parsing exception occasionally when running in multithread, while the same program works well in single thread. And if i copy the failed packet to unit test, it also passes. Would you mind taking a look?
My IP/TCP structure definition is:
"skip:14; // skip bytes till the frame\n"
+"bit:4 InternetHeaderLength;"
+"bit:4 Version;"
+"bit:2 ECN;"
+"bit:6 DSCP;"
+"ushort TotalPacketLength;"
+"ushort Identification;"
+"bit:8 IPFlagsAndFragmentOffset_low;"
+"bit:5 IPFlagsAndFragmentOffset_high;"
+"bit:1 MoreFragment;"
+"bit:1 DonotFragment;"
+"bit:1 ReservedBit;"
+"ubyte TTL;"
+"ubyte Protocol;"
+"ushort HeaderChecksum;"
+"int SourceAddress;"
+"int DestinationAddress;"
+"byte [(InternetHeaderLength-5)*4] Options;"
"skip:34; // skip bytes till the frame\n"
+ "ushort SourcePort;"
+ "ushort DestinationPort;"
+ "int SequenceNumber;"
+ "int AcknowledgementNumber;"
+ "bit:1 NONCE;"
+ "bit:3 RESERVED;"
+ "bit:4 HLEN;"
+ "bit:1 FIN;"
+ "bit:1 SYN;"
+ "bit:1 RST;"
+ "bit:1 PSH;"
+ "bit:1 ACK;"
+ "bit:1 URG;"
+ "bit:1 ECNECHO;"
+ "bit:1 CWR;"
+ "ushort WindowSize;"
+ "ushort TCPCheckSum;"
+ "ushort UrgentPointer;"
+ "byte [HLEN*4-20] Option;"
+ "byte [_] Data;"
And the exception i got is:
com.igormaznitsa.jbbp.exceptions.JBBPParsingException: Detected negative calculated array length for field 'options' [-80 (0xFFFFFFB0)]
at com.igormaznitsa.jbbp.JBBPParser.assertArrayLength(JBBPParser.java:101)
at com.igormaznitsa.jbbp.JBBPParser.parseStruct(JBBPParser.java:176)
at com.igormaznitsa.jbbp.JBBPParser.parse(JBBPParser.java:489)
at com.igormaznitsa.jbbp.JBBPParser.parse(JBBPParser.java:515)
and
JBBPParsingException while parsing, Detected negative calculated array length for field 'option' [-68 (0xFFFFFFBC)]
Thanks in advance!
interesting, the parser is stateless one and it doesn't share its state during parsing, is it possible that you make reading of data from the same input stream in another thread simultaneously?
thank you for the script example, I will add test for such case anyway
yep, I can reproduce it, will investigate
I have fixed the issue, it was for non thread-safe behaviour of expression calculator
So quick! Thank you so much!