Skip to content

Commit 84d6c5d

Browse files
fix: Improve handling of broken accept headers in MediaTypeHeaderDelegate.parse(..) within resteasy-reactive
Previously, a "broken" MIME-type in an access header could trigger an StringIndexOutOfBoundsException during MediaTypeHeaderDelegate.parse(..) instead of the more suitable IllegalArgumentException. Example: "Accept: x; /x" This PR now throws an IllegalArgumentException in case of a broken MIME-type like in the example. Fixes quarkusio#36159
1 parent 1e3a64b commit 84d6c5d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ private static MediaType internalParse(String type) {
8080
} else {
8181
major = type.substring(0, typeIndex);
8282
if (paramIndex > -1) {
83+
if (typeIndex + 1 > paramIndex) {
84+
throw new IllegalArgumentException("Failed to parse media type " + type);
85+
}
8386
subtype = type.substring(typeIndex + 1, paramIndex);
8487
} else {
8588
subtype = type.substring(typeIndex + 1);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.jboss.resteasy.reactive.common.headers;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class MediaTypeHeaderDelegateTest {
7+
8+
public void parsingBrokenMediaTypeShouldThrowIllegalArgumentException_minimized() {
9+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
10+
MediaTypeHeaderDelegate.parse("x; /x");
11+
});
12+
}
13+
14+
@Test
15+
public void parsingBrokenMediaTypeShouldThrowIllegalArgumentException_actual() {
16+
Assertions.assertThrows(IllegalArgumentException.class, () -> {
17+
MediaTypeHeaderDelegate.parse("() { ::}; echo \"NS:\" $(/bin/sh -c \"expr 123456 - 123456\")");
18+
});
19+
}
20+
21+
}

0 commit comments

Comments
 (0)