zjncs opened a new pull request, #11109: URL: https://github.com/apache/rocketmq/pull/11109
## Motivation `TraceDataEncoder.decoderFromTraceDataString` splits a trace-topic payload into lines and indexes fixed positions per line type — the Pub branch unconditionally reads `line[0]..line[11]` and calls `Long.parseLong`, `Integer.parseInt`, `MessageType.values()[...]`; the EndTransaction branch additionally does `LocalTransactionState.valueOf(line[11])`. There is no per-line length or format validation. This is reached from `mqadmin queryMsgTraceById` (`QueryMsgTraceByIdSubCommand` → `TraceView.decodeFromTraceTransData` → this decoder), which scans the trace topic. The trace topic is a plain topic any producer can publish to, and the decoder itself carries `compatible with the old version` branches precisely because the field layout differs across client versions. One truncated, corrupted or foreign-version line throws and aborts the decode of every remaining context in the payload, failing the whole command. ## Modification Wrap the per-line parsing in try/catch: a malformed line is skipped with a warn log (including the offending line), and the remaining contexts are still decoded and returned. ## Test Evidence Fail-before (unpatched develop, new tests in `TraceDataEncoderTest`): ``` #testDecoderSkipsTruncatedLineAndKeepsRemaining Tests run: 1, Errors: 1 - java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4 #testDecoderSkipsNonNumericFieldAndKeepsRemaining Tests run: 1, Errors: 1 - java.lang.NumberFormatException: For input string: "not-a-timestamp" #testDecoderSkipsOutOfRangeMsgTypeOrdinalAndKeepsRemaining Tests run: 1, Errors: 1 - java.lang.ArrayIndexOutOfBoundsException: Index 99 out of bounds for length 5 ``` Pass-after: ``` mvn -q -pl client test -Dtest='TraceDataEncoderTest,TraceViewTest' Tests run: 12, Failures: 0, Errors: 0, Skipped: 0 ``` No associated issue (self-discovered during a client-module self-audit). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
