From 7d45cd4f704d49ae901bc9f990dda09c5c4f6a21 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Sat, 19 Aug 2023 13:08:49 -0400 Subject: [PATCH 1/4] [JENKINS-61452] Tolerate corrupt Base64 in `PlainTextConsoleOutputStream` (#8378) (cherry picked from commit 7f3fa048ca0c8094a552d02d5863c49fc06ea42a) --- .../console/PlainTextConsoleOutputStream.java | 12 ++++++++- .../console/AnnotatedLargeTextTest.java | 26 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/console/PlainTextConsoleOutputStream.java b/core/src/main/java/hudson/console/PlainTextConsoleOutputStream.java index f3b5bd8adf7e..70bc85b7b110 100644 --- a/core/src/main/java/hudson/console/PlainTextConsoleOutputStream.java +++ b/core/src/main/java/hudson/console/PlainTextConsoleOutputStream.java @@ -28,6 +28,10 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.Charset; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.lang.StringEscapeUtils; /** * Filters out console notes. @@ -36,6 +40,8 @@ */ public class PlainTextConsoleOutputStream extends LineTransformationOutputStream.Delegating { + private static final Logger LOGGER = Logger.getLogger(PlainTextConsoleOutputStream.class.getName()); + /** * */ @@ -64,7 +70,11 @@ protected void eol(byte[] in, int sz) throws IOException { int rest = sz - next; ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest); - ConsoleNote.skip(new DataInputStream(b)); + try { + ConsoleNote.skip(new DataInputStream(b)); + } catch (IOException x) { + LOGGER.log(Level.FINE, "Failed to skip annotation from \"" + StringEscapeUtils.escapeJava(new String(in, next, rest, Charset.defaultCharset())) + "\"", x); + } int bytesUsed = rest - b.available(); // bytes consumed by annotations written += bytesUsed; diff --git a/test/src/test/java/hudson/console/AnnotatedLargeTextTest.java b/test/src/test/java/hudson/console/AnnotatedLargeTextTest.java index dcd3b96c3210..825bd2b60460 100644 --- a/test/src/test/java/hudson/console/AnnotatedLargeTextTest.java +++ b/test/src/test/java/hudson/console/AnnotatedLargeTextTest.java @@ -27,6 +27,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.matchesRegex; import static org.junit.Assert.assertEquals; import hudson.MarkupText; @@ -52,7 +53,7 @@ public class AnnotatedLargeTextTest { public static JenkinsRule r = new JenkinsRule(); @Rule - public LoggerRule logging = new LoggerRule().record(ConsoleAnnotationOutputStream.class, Level.FINE).capture(100); + public LoggerRule logging = new LoggerRule().record(ConsoleAnnotationOutputStream.class, Level.FINE).record(PlainTextConsoleOutputStream.class, Level.FINE).capture(100); @Test public void smokes() throws Exception { @@ -138,6 +139,29 @@ public void badMac() throws Exception { + "AAA\\u001B[0myour home.\\n\"")); // TODO assert that this is IOException: MAC mismatch } + @Issue("JENKINS-61452") + @Test + public void corruptedNote() throws Exception { + ByteBuffer buf = new ByteBuffer(); + PrintStream ps = new PrintStream(buf, true, StandardCharsets.UTF_8); + ps.print("Some text.\n"); + ps.print("Go back to " + TestNote.encodeTo("/root", "your home") + ".\n"); + ps.print("More text.\n"); + String original = buf.toString(); + String corrupted = original.replace("+", "\u0000"); + buf = new ByteBuffer(); + buf.write(corrupted.getBytes()); + AnnotatedLargeText text = new AnnotatedLargeText<>(buf, StandardCharsets.UTF_8, true, null); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + text.writeLogTo(0, baos); + assertThat(baos.toString(StandardCharsets.UTF_8), matchesRegex("Some text[.]\nGo back to .*your home[.]\nMore text[.]\n")); + assertThat(logging.getMessages(), hasItem(matchesRegex("Failed to skip annotation from .+"))); + StringWriter w = new StringWriter(); + text.writeHtmlTo(0, w); + assertThat(w.toString(), matchesRegex("Some text[.]\nGo back to .*your home[.]\nMore text[.]\n")); + assertThat(logging.getMessages(), hasItem(matchesRegex("Failed to resurrect annotation from .+"))); + } + /** Simplified version of {@link HyperlinkNote}. */ static class TestNote extends ConsoleNote { private final String url; From 5f47d53aedbe898b2051535f7af72e1dbd680ecc Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Tue, 8 Aug 2023 13:06:42 +0100 Subject: [PATCH 2/4] [JENKINS-71238] New login page breaks `login-theme-plugin` (#8341) Move simple-header out (cherry picked from commit 4ccb66b0f8c0ba7fed28e7cccf8903b0f4e58dae) --- .../security/HudsonPrivateSecurityRealm/signup.jelly | 7 ++++++- .../model/DefaultSimplePageDecorator/simple-header.jelly | 7 +------ core/src/main/resources/jenkins/model/Jenkins/login.jelly | 7 ++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/src/main/resources/hudson/security/HudsonPrivateSecurityRealm/signup.jelly b/core/src/main/resources/hudson/security/HudsonPrivateSecurityRealm/signup.jelly index 45339b4d3d7a..1e550e3a1497 100644 --- a/core/src/main/resources/hudson/security/HudsonPrivateSecurityRealm/signup.jelly +++ b/core/src/main/resources/hudson/security/HudsonPrivateSecurityRealm/signup.jelly @@ -52,11 +52,16 @@ THE SOFTWARE. - +