You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2023/02/03 12:19:06 UTC
[daffodil] branch main updated: Reduce the maximum length of xs:hexBinary to Int.MaxValue / 2
This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new d62be6482 Reduce the maximum length of xs:hexBinary to Int.MaxValue / 2
d62be6482 is described below
commit d62be6482c8594e8940832005401408b64c169dd
Author: Steve Lawrence <sl...@apache.org>
AuthorDate: Thu Feb 2 12:27:52 2023 -0500
Reduce the maximum length of xs:hexBinary to Int.MaxValue / 2
xs:hexBinary is represented as an Array[Byte], which has a Java
implementation maximum length of Int.MaxValue and is what we currently
limit hexBinary data to. However, when we output hexBinary bytes to an
infoset we convert it to a String, with each byte converted to two
characters, effectively doubling the length. Since Java Strings have the
same Int.MaxValue length limit, the maximum size of hexBinary that we
can actually support is only half of Int.MaxValue. This changes the
default and maximum value of the maxHexBinaryLengthInBytes tunable, and
thus the length of xs:hexBinary elements, to 1073741823.
Backwards/Compatibility:
The default and maximum value of the maxHexBinaryLengthInBytes tunable,
and thus the maximum length of xs:hexBinary elements, is reduced in half
from 2147483647 to 1073741823 bytes. Schemas requiring larger values
should switch to the Binary Large Object extension or convert the single
large hexBinary element to an array of multiple smaller hexBinary
elements.
DAFFODIL-2782
---
daffodil-lib/src/main/scala/org/apache/daffodil/util/Misc.scala | 2 ++
.../src/main/resources/org/apache/daffodil/xsd/dafext.xsd | 8 +++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/util/Misc.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/util/Misc.scala
index 42ce8488a..788216985 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/util/Misc.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/util/Misc.scala
@@ -37,6 +37,7 @@ import java.nio.file.Paths
import scala.collection.JavaConverters._
import org.apache.daffodil.equality._
+import org.apache.daffodil.exceptions.Assert
/**
* Various reusable utilities that I couldn't easily find a better place for.
@@ -310,6 +311,7 @@ object Misc {
private val hexLookup = "0123456789ABCDEF".toArray
def bytes2Hex(bytes: Array[Byte]): String = {
+ Assert.invariant(bytes.length <= Int.MaxValue / 2)
val hexArr = new Array[Char](bytes.length * 2)
var bytIdx = 0
var hexIdx = 0
diff --git a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
index 1947568a1..3fdb5dfc5 100644
--- a/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
+++ b/daffodil-propgen/src/main/resources/org/apache/daffodil/xsd/dafext.xsd
@@ -308,7 +308,7 @@
</xs:documentation>
</xs:annotation>
</xs:element>
- <xs:element name="maxHexBinaryLengthInBytes" default="2147483647" minOccurs="0">
+ <xs:element name="maxHexBinaryLengthInBytes" default="1073741823" minOccurs="0">
<xs:annotation>
<xs:documentation>
The maximum size allowed for an xs:hexBinary element.
@@ -317,6 +317,12 @@
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
+ <!--
+ The maxInclusive value is set to (Int.MaxValue / 2) since each byte in
+ hex binary becomes 2 hex chars, and the maximum length of a string in
+ Java is Int.MaxValue
+ -->
+ <xs:maxInclusive value="1073741823" />
</xs:restriction>
</xs:simpleType>
</xs:element>