diff --git a/src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java b/src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java index a8f7c8ac..0102b2b0 100644 --- a/src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java +++ b/src/main/java/org/jenkinsci/plugins/durabletask/FileMonitoringTask.java @@ -393,7 +393,12 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException, Interr return null; } else { try { - return Integer.valueOf(text); + long value = Long.parseLong(text); + if (value > Integer.MAX_VALUE) { + LOGGER.warning("ErrorCode greater than max integer detected, limited to max value"); + value = Integer.MAX_VALUE; + } + return (Integer) (int) value; } catch (NumberFormatException x) { throw new IOException("corrupted content in " + f + ": " + x, x); } diff --git a/src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java b/src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java index 4691ca91..bd055852 100644 --- a/src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java +++ b/src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java @@ -114,6 +114,22 @@ private void testWithPath(String path) throws Exception { c.cleanup(ws); } + @Test public void exitCommandUnsignedInt() throws Exception { + Controller c = new WindowsBatchScript("echo hello world\r\nexit 3221225477").launch(new EnvVars(), ws, launcher, listener); + awaitCompletion(c); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + c.writeLog(ws, baos); + if (enableBinary) { + assertEquals(Integer.valueOf(Integer.MAX_VALUE), c.exitStatus(ws, launcher, listener)); + } else { + assertEquals(Integer.valueOf(-1073741819), c.exitStatus(ws, launcher, listener)); + } + + String log = baos.toString(); + assertTrue(log, log.contains("hello world")); + c.cleanup(ws); + } + @Test public void exitBCommandAfterError() throws Exception { Controller c = new WindowsBatchScript("cmd /c exit 42\r\nexit /b").launch(new EnvVars(), ws, launcher, listener); awaitCompletion(c);