You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2001/04/29 20:17:20 UTC

[Bug 1573] New - xsd:binary encoding validation does not work. Base64 validation incorrectly rejects zero-length strings. Error in error message.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1573

*** shadow/1573	Sun Apr 29 11:17:19 2001
--- shadow/1573.tmp.15000	Sun Apr 29 11:17:20 2001
***************
*** 0 ****
--- 1,113 ----
+ +============================================================================+
+ | xsd:binary encoding validation does not work.  Base64 validation incorrect |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1573                        Product: Xerces-J                |
+ |       Status: NEW                         Version: cvs extract (inc        |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version: Linux                   |
+ |     Priority:                           Component: Schema-Datatypes        |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xerces-j-dev@xml.apache.org                                  |
+ |  Reported By: pdw@decisionsoft.com                                         |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL: http://www.decisionsoft.com/pdw/xerces-j-base64.diff         |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ CVS checkout dated 29/04/01.
+ 
+ 1. FACET_ENCODING never gets set, so no validation of the encoding ever gets set.
+ 2. Base64 validation incorrectly rejects zero-length strings.
+ 3. There is an error in the error message for this validation.
+ 
+ The patch below fixes all these bugs: (also at
+ http://www.decisionsoft.com/pdw/xerces-j-base64.diff)
+ 
+ 
+ diff -cr xml-xerces-clean/java/src/org/apache/xerces/utils/Base64.java
+ xml-xerces/java/src/org/apache/xerces/utils/Base64.java
+ *** xml-xerces-clean/java/src/org/apache/xerces/utils/Base64.java	Tue Apr 24 16:43:24 2001
+ --- xml-xerces/java/src/org/apache/xerces/utils/Base64.java	Tue Apr 24 15:08:51 2001
+ ***************
+ *** 133,139 ****
+       public static boolean isArrayByteBase64( byte[] arrayOctect ) {
+           int length = arrayOctect.length;
+           if ( length == 0 )
+ !             return false;
+           for ( int i=0; i < length; i++ ) {
+               if ( Base64.isBase64( arrayOctect[i] ) == false)
+                   return false;
+ --- 133,141 ----
+       public static boolean isArrayByteBase64( byte[] arrayOctect ) {
+           int length = arrayOctect.length;
+           if ( length == 0 )
+ !             // a zero-length Base64 string is valid according to the RFC
+ !             //  -- pdw@decisionsoft.com 2001-04-24
+ !             return true;
+           for ( int i=0; i < length; i++ ) {
+               if ( Base64.isBase64( arrayOctect[i] ) == false)
+                   return false;
+ diff -cr
+ xml-xerces-clean/java/src/org/apache/xerces/validators/datatype/BinaryDatatypeValidator.java
+ xml-xerces/java/src/org/apache/xerces/validators/datatype/BinaryDatatypeValidator.java
+ *** xml-xerces-clean/java/src/org/apache/xerces/validators/datatype/BinaryDatatypeValidator.java	Tue Apr 24 16:43:45 2001
+ --- xml-xerces/java/src/org/apache/xerces/validators/datatype/BinaryDatatypeValidator.java	Tue Apr 24 16:36:35 2001
+ ***************
+ *** 138,144 ****
+                       fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
+                       fEnumeration = (Vector)facets.get(key);
+                   } else if (key.equals(SchemaSymbols.ELT_ENCODING )) {
+ !                     fFacetsDefined += DatatypeValidator.FACET_MAXINCLUSIVE;
+                       fEncoding = (String)facets.get(key);
+                   } else {
+                       throw new InvalidDatatypeFacetException();
+ --- 138,144 ----
+                       fFacetsDefined += DatatypeValidator.FACET_ENUMERATION;
+                       fEnumeration = (Vector)facets.get(key);
+                   } else if (key.equals(SchemaSymbols.ELT_ENCODING )) {
+ !                     fFacetsDefined += DatatypeValidator.FACET_ENCODING;
+                       fEncoding = (String)facets.get(key);
+                   } else {
+                       throw new InvalidDatatypeFacetException();
+ ***************
+ *** 182,198 ****
+           if ( this.fBaseValidator != null ) {//validate against parent type if any
+               this.fBaseValidator.validate( content, state );
+           }
+ -
+           if (((fFacetsDefined & DatatypeValidator.FACET_ENCODING) != 0 ) ){
+ //Encode defined then validate
+               if ( fEncoding.equals( SchemaSymbols.ATTVAL_BASE64)){ //Base64
+                   if ( Base64.isBase64( content ) == false ) {
+                       throw new InvalidDatatypeValueException( "Value '"+
+ !                                                                 content+ "'
+ must be" + "is not encoded in Base64" );
+                   }
+               } else { //HexBin
+                   if ( HexBin.isHex( content ) == false ){
+                       throw new InvalidDatatypeValueException( "Value '"+
+ !                                                                 content+ "'
+ must be" + "is not encoded in Hex" );
+                   }
+               }
+           }
+ --- 182,197 ----
+           if ( this.fBaseValidator != null ) {//validate against parent type if any
+               this.fBaseValidator.validate( content, state );
+           }
+           if (((fFacetsDefined & DatatypeValidator.FACET_ENCODING) != 0 ) ){
+ //Encode defined then validate
+               if ( fEncoding.equals( SchemaSymbols.ATTVAL_BASE64)){ //Base64
+                   if ( Base64.isBase64( content ) == false ) {
+                       throw new InvalidDatatypeValueException( "Value '"+
+ !                                                                 content+ "'
+ must be encoded in Base64" );
+                   }
+               } else { //HexBin
+                   if ( HexBin.isHex( content ) == false ){
+                       throw new InvalidDatatypeValueException( "Value '"+
+ !                                                                 content+ "'
+ must be encoded in Hex" );
+                   }
+               }
+           }

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org