This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 29d34f0a75 Ignore empty list elements when parsing the Range header
(#1106)
29d34f0a75 is described below
commit 29d34f0a757c60add420897bd01be137532bf3d1
Author: Arturo Bernal <[email protected]>
AuthorDate: Wed Nov 4 11:35:25 2026 +0100
Ignore empty list elements when parsing the Range header (#1106)
RFC 9110, section 5.6.1.2 requires a recipient to parse and ignore
empty list elements. The Range parser rejected a value such as
"bytes=0-9,,10-19", so the Range header was ignored for it. Skip the
empty elements and still reject a list that has no element at all.
---
.../org/apache/tomcat/util/http/parser/Ranges.java | 13 ++++++++++++
.../apache/tomcat/util/http/parser/TestRanges.java | 24 ++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/java/org/apache/tomcat/util/http/parser/Ranges.java
b/java/org/apache/tomcat/util/http/parser/Ranges.java
index 4e21a2a9a1..5c9e3dbcd1 100644
--- a/java/org/apache/tomcat/util/http/parser/Ranges.java
+++ b/java/org/apache/tomcat/util/http/parser/Ranges.java
@@ -164,6 +164,14 @@ public class Ranges {
SkipResult skipResult;
do {
+ // Empty list elements must be ignored (RFC 9110, section 5.6.1.2)
+ while ((skipResult = HttpParser.skipConstant(input, ",")) ==
SkipResult.FOUND) {
+ // Skip
+ }
+ if (skipResult == SkipResult.EOF) {
+ break;
+ }
+
long start;
long end;
try {
@@ -196,6 +204,11 @@ public class Ranges {
}
} while (skipResult == SkipResult.FOUND);
+ if (entries.isEmpty()) {
+ // The list contained empty elements only
+ return null;
+ }
+
return new Ranges(units, entries);
}
}
diff --git a/test/org/apache/tomcat/util/http/parser/TestRanges.java
b/test/org/apache/tomcat/util/http/parser/TestRanges.java
index 77d8757b10..7bed77c2cf 100644
--- a/test/org/apache/tomcat/util/http/parser/TestRanges.java
+++ b/test/org/apache/tomcat/util/http/parser/TestRanges.java
@@ -135,6 +135,30 @@ public class TestRanges {
}
+ @Test
+ public void testValid05() throws Exception {
+ // RFC 9110, section 5.6.1.2: empty list elements must be ignored
+ doTestEmptyListElements("bytes=0-9,,10-19");
+ doTestEmptyListElements("bytes=0-9, ,10-19");
+ doTestEmptyListElements("bytes=,0-9,10-19");
+ doTestEmptyListElements("bytes=0-9,10-19,");
+ doTestEmptyListElements("bytes= , 0-9 ,, 10-19 , ");
+ }
+
+
+ @Test
+ public void testInvalid09() throws Exception {
+ // A list that has no elements at all is not a range set
+ doTestInvalid("bytes=,");
+ doTestInvalid("bytes=, ,");
+ }
+
+
+ private void doTestEmptyListElements(String s) throws IOException {
+ compareRanges(parse("bytes=0-9,10-19"), parse(s));
+ }
+
+
private void doTestInvalid(String s) throws IOException {
Ranges r = parse(s);
Assert.assertNull(r);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]