From dfa53c573608c3cd0a5e500b02d6959c0590c8e6 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Tue, 24 Nov 2026 13:17:15 +0100 Subject: [PATCH] Accept a page directive buffer size of 0kb A buffer value of "0kb" was rejected as invalid, so a page using it failed with a translation error. The JSP specification only requires the size to be expressed in kilobytes, with a mandatory "kb" suffix, and output to be buffered with a buffer size not less than that specified. A size of 0kb is therefore valid, and it results in the page not being buffered, as it did before. Negative sizes and sizes that would overflow when converted to bytes are still rejected. --- java/org/apache/jasper/compiler/PageInfo.java | 8 ++++---- test/org/apache/jasper/compiler/TestPageInfo.java | 5 ++--- webapps/docs/changelog.xml | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/java/org/apache/jasper/compiler/PageInfo.java b/java/org/apache/jasper/compiler/PageInfo.java index a943f1f7e517..9162650c9d2b 100644 --- a/java/org/apache/jasper/compiler/PageInfo.java +++ b/java/org/apache/jasper/compiler/PageInfo.java @@ -621,10 +621,10 @@ public void setBufferValue(String value, Node n, ErrorDispatcher err) throws Jas try { @SuppressWarnings("null") // value can't be null here int k = Integer.parseInt(value.substring(0, value.length() - 2)); - // JSP.7.2.1 requires a positive integer. Values outside this - // range are invalid in themselves and would additionally - // overflow the multiplication by 1024 below. - if (k <= 0 || k > Integer.MAX_VALUE / 1024) { + // Zero is a valid size and means no buffering. Negative sizes + // are invalid and larger sizes would overflow the + // multiplication by 1024 below. + if (k < 0 || k > Integer.MAX_VALUE / 1024) { if (n == null) { err.jspError("jsp.error.page.invalid.buffer"); } else { diff --git a/test/org/apache/jasper/compiler/TestPageInfo.java b/test/org/apache/jasper/compiler/TestPageInfo.java index 4a97557baee6..c6ccc424275d 100644 --- a/test/org/apache/jasper/compiler/TestPageInfo.java +++ b/test/org/apache/jasper/compiler/TestPageInfo.java @@ -36,13 +36,12 @@ public void testBufferValid() throws Exception { @Test public void testBufferZero() throws Exception { - // JSP.7.2.1 requires a positive integer - doTestBuffer("zero", 500, "invalid value for buffer"); + // A buffer size of 0kb is valid and means no buffering + doTestBuffer("zero", 200, null); } @Test public void testBufferNegative() throws Exception { - // JSP.7.2.1 requires a positive integer doTestBuffer("negative", 500, "invalid value for buffer"); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index f0d04f8c55be..2ca6d963bb5a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -458,6 +458,11 @@ language specification when expr-a is a literal null. (markt) + + Accept a page directive buffer size of 0kb again. The JSP + specification only requires the size to be expressed in kilobytes. + Pull request 1271 provided by Arturo Bernal. +