Repository: xlate/staedi
Pull request #361 (2023-05-04 23:22:03)

fix: correct writer array bounds check for zero-length output

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=xlate_staedi&pullRequest=361)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=xlate_staedi&pullRequest=361&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=xlate_staedi&pullRequest=361&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=xlate_staedi&pullRequest=361&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=xlate_staedi&pullRequest=361&resolved=false&types=CODE_SMELL)

[![100.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/100-16px.png '100.0%')](https://sonarcloud.io/component_measures?id=xlate_staedi&pullRequest=361&metric=new_coverage&view=list) [100.0% Coverage](https://sonarcloud.io/component_measures?id=xlate_staedi&pullRequest=361&metric=new_coverage&view=list)  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=xlate_staedi&pullRequest=361&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=xlate_staedi&pullRequest=361&metric=new_duplicated_lines_density&view=list)



Patch:
diff --git a/src/main/java/io/xlate/edi/internal/stream/StaEDIStreamWriter.java b/src/main/java/io/xlate/edi/internal/stream/StaEDIStreamWriter.java
index 21459a7..39de8e4 100644
--- a/src/main/java/io/xlate/edi/internal/stream/StaEDIStreamWriter.java
+++ b/src/main/java/io/xlate/edi/internal/stream/StaEDIStreamWriter.java
@@ -186,7 +186,7 @@ public class StaEDIStreamWriter implements EDIStreamWriter, ElementDataHandler,
     }
 
     private static void ensureArgs(int arrayLength, int start, int end) {
-        if (start < 0 || start >= arrayLength || end > arrayLength) {
+        if (start < 0 || (start > 0 && start >= arrayLength) || end > arrayLength) {
             throw new IndexOutOfBoundsException();
         }
 


Test patch:
diff --git a/src/test/java/io/xlate/edi/internal/bind/AcknowledgementBindTest.java b/src/test/java/io/xlate/edi/internal/bind/AcknowledgementBindTest.java
index 66859ad..95a9dac 100644
--- a/src/test/java/io/xlate/edi/internal/bind/AcknowledgementBindTest.java
+++ b/src/test/java/io/xlate/edi/internal/bind/AcknowledgementBindTest.java
@@ -32,6 +32,9 @@ class AcknowledgementBindTest {
         Marshaller m = context.createMarshaller();
         EDIOutputFactory oFactory = EDIOutputFactory.newFactory();
         oFactory.setProperty(EDIOutputFactory.PRETTY_PRINT, Boolean.TRUE);
+        oFactory.setErrorReporter((error, writer, location, data, typeReference) -> {
+            // ignore
+        });
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         EDIStreamWriter writer = oFactory.createEDIStreamWriter(out);
         XMLStreamWriter xmlWriter = oFactory.createXMLStreamWriter(writer);
@@ -49,18 +52,23 @@ class AcknowledgementBindTest {
         header.ISA09 = "200301";
         header.ISA10 = "1430";
         header.ISA11 = "^";
-        header.ISA12 = "00501";
+        header.ISA12 = "00704";
         header.ISA13 = "000000001";
         header.ISA14 = "0";
         header.ISA15 = "P";
         header.ISA16 = ":";
 
+        ISX syntaxExtension = new ISX();
+        syntaxExtension.ISX01 = "\\";
+        syntaxExtension.ISX02 = "";
+
         IEA trailer = new IEA();
         trailer.IEA01 = "0";
         trailer.IEA02 = "000000001";
 
         Interchange interchange = new Interchange();
         interchange.header = header;
+        interchange.syntaxExtension = syntaxExtension;
         interchange.trailer = trailer;
 
         m.marshal(interchange, xmlWriter);
@@ -102,6 +110,9 @@ class AcknowledgementBindTest {
         @XmlElement(name = "ISA", namespace = EDINamespaces.SEGMENTS)
         ISA header;
 
+        @XmlElement(name = "ISX", namespace = EDINamespaces.SEGMENTS)
+        ISX syntaxExtension;
+
         @XmlElement(name = "IEA", namespace = EDINamespaces.SEGMENTS)
         IEA trailer;
     }
@@ -142,6 +153,14 @@ class AcknowledgementBindTest {
         String ISA16;
     }
 
+    @XmlType(namespace = EDINamespaces.SEGMENTS, propOrder = {})
+    static class ISX {
+        @XmlElement(namespace = EDINamespaces.ELEMENTS)
+        String ISX01;
+        @XmlElement(namespace = EDINamespaces.ELEMENTS)
+        String ISX02;
+    }
+
     @XmlType(namespace = EDINamespaces.SEGMENTS, propOrder = {})
     static class IEA {
         @XmlElement(namespace = EDINamespaces.ELEMENTS)