Repository navigation
fix: prevent ArrayIndexOutOfBoundsException in K8s ingress protocol annotation parsing - #6892
Conversation
…nnotation parsing - DivideIngressParser: add bounds check when indexing protocol array, fall back to "http://" when annotation has fewer entries than endpoint addresses - DubboIngressParser: fix NPE when annotation is missing, fix double-increment bug where protocols[i++] was evaluated twice in one expression - Add unit tests covering missing, exact, fewer, mixed, and empty annotation scenarios Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Clean fix — the double-increment in I did a variant search across the k8s parsers: One minor pre-existing edge case (consistent across all parsers incl. |
Aias00
left a comment
There was a problem hiding this comment.
Thanks @wy471x!
Both fixes are correct and close real defects:
- DivideIngressParser:
protocol[i++]with no bounds check threwArrayIndexOutOfBoundsExceptionwhenevershenyu.apache.org/upstreams-protocolhad fewer entries than endpoint addresses. The indexed loop with thei >= protocol.lengthfallback tohttp://is the right behavior, and incrementingiper address (rather than only when a protocol was assigned) keeps the annotation entries aligned with their addresses. - DubboIngressParser: the old
Objects.isNull(protocols[i++]) ? "dubbo://" : protocols[i++]both double-incrementedi(skipping entries and eventually going out of bounds) and NPE'd when the annotation was missing. The single bounds-checkedprotocols[i]plus theannotationsnull/containsKeyguard fix all three problems at once, withdubbo://as the sensible default.
Tests cover missing/exact/fewer/mixed/empty annotation scenarios for both parsers and assert on the actual upstream protocol values, which is exactly the right level of verification.
shenyu-kubernetes-controller/src/test/java/org/apache/shenyu/k8s/parser/DubboIngressParserTest.java with different test sets, so whichever merges second will need a rebase that merges the two test classes together (this PR's file also doesn't include the parseIngressRule null-safety tests from #6896). Worth reconciling before either lands.
LGTM, approving.
…nnotation parsing (apache#6892) - DivideIngressParser: add bounds check when indexing protocol array, fall back to "http://" when annotation has fewer entries than endpoint addresses - DubboIngressParser: fix NPE when annotation is missing, fix double-increment bug where protocols[i++] was evaluated twice in one expression - Add unit tests covering missing, exact, fewer, mixed, and empty annotation scenarios Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Co-authored-by: zhengpeng <847850277@qq.com> Co-authored-by: Liming Deng <liming.d.pro@gmail.com>
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
Bug Fixes
DivideIngressParser.java — The protocol array was indexed with protocol[i++] without any bounds check. When the shenyu.apache.org/upstreams-protocol annotation had fewer entries
than endpoint addresses, it threw ArrayIndexOutOfBoundsException. Fixed by switching to an indexed for-loop with a bounds guard (i >= protocol.length) that falls back to
"http://".
DubboIngressParser.java — Two bugs fixed:
entries and AIOOBE. Replaced with a single bounds-checked protocols[i].
Unit Tests
close #6485