directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r887015 - /directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
Date Fri, 04 Dec 2009 00:32:45 GMT
Author: elecharny
Date: Fri Dec  4 00:32:44 2009
New Revision: 887015

URL: http://svn.apache.org/viewvc?rev=887015&view=rev
Log:
Fixed a nasty bug in the binary values serialization, when the normalized value was different
from the UP value : we got a OOM error as the length of the normalized value was wrongly encoded
as a char, not an int.

Modified:
    directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java

Modified: directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java?rev=887015&r1=887014&r2=887015&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-entry/src/main/java/org/apache/directory/server/core/entry/ServerBinaryValue.java
Fri Dec  4 00:32:44 2009
@@ -54,7 +54,7 @@
 {
     /** Used for serialization */
     private static final long serialVersionUID = 2L;
-    
+
     /** logger for reporting errors that might not be handled properly upstream */
     private static final Logger LOG = LoggerFactory.getLogger( ServerBinaryValue.class );
 
@@ -74,11 +74,11 @@
      */
     protected String logAssert( String message )
     {
-        LOG.error(  message );
+        LOG.error( message );
         return message;
     }
 
-    
+
     /**
      *  Check the attributeType member. It should not be null, 
      *  and it should contains a syntax.
@@ -89,7 +89,7 @@
         {
             return "The AttributeType parameter should not be null";
         }
-        
+
         if ( attributeType.getSyntax() == null )
         {
             return "There is no Syntax associated with this attributeType";
@@ -98,7 +98,7 @@
         return null;
     }
 
-    
+
     // -----------------------------------------------------------------------
     // Constructors
     // -----------------------------------------------------------------------
@@ -110,7 +110,7 @@
     public ServerBinaryValue( AttributeType attributeType )
     {
         super();
-        
+
         if ( attributeType == null )
         {
             throw new IllegalArgumentException( "The AttributeType parameter should not be
null" );
@@ -151,7 +151,7 @@
      * @param wrapped the value to wrap which can be null
      * @param normalizedValue the normalized value
      */
-    /** No protection */ 
+    /** No protection */
     ServerBinaryValue( AttributeType attributeType, byte[] wrapped, byte[] normalizedValue,
boolean same, boolean valid )
     {
         super( wrapped );
@@ -159,7 +159,7 @@
         this.attributeType = attributeType;
         this.normalizedValue = normalizedValue;
         this.valid = valid;
-        this.same = same;
+        this.same = same;
         //this.oid = attributeType.getOid();
     }
 
@@ -174,11 +174,11 @@
             // Bypass the normalization if it has already been done. 
             return;
         }
-        
+
         if ( wrapped != null )
         {
             Normalizer normalizer = getNormalizer();
-    
+
             if ( normalizer == null )
             {
                 normalizedValue = wrapped;
@@ -200,7 +200,7 @@
         }
     }
 
-    
+
     /**
      * Gets the normalized (canonical) representation for the wrapped string.
      * If the wrapped String is null, null is returned, otherwise the normalized
@@ -246,7 +246,7 @@
      *
      * @return gets the normalized value
      */
-    public byte[] getNormalizedValue() 
+    public byte[] getNormalizedValue()
     {
         if ( isNull() )
         {
@@ -302,7 +302,7 @@
 
         if ( normalizedValue != null )
         {
-            byte[] copy = new byte[ normalizedValue.length ];
+            byte[] copy = new byte[normalizedValue.length];
             System.arraycopy( normalizedValue, 0, copy, 0, normalizedValue.length );
             return copy;
         }
@@ -330,10 +330,10 @@
         }
 
         valid = attributeType.getSyntax().getSyntaxChecker().isValidSyntax( getReference()
);
-        
+
         return valid;
     }
-    
+
 
     /**
      *
@@ -356,7 +356,7 @@
         }
         else
         {
-            if ( ( value == null ) || value.isNull() ) 
+            if ( ( value == null ) || value.isNull() )
             {
                 return 1;
             }
@@ -369,28 +369,29 @@
             try
             {
                 Comparator<? super byte[]> comparator = getLdapComparator();
-                
+
                 if ( comparator != null )
                 {
-                    return comparator.compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference()
);
+                    return comparator
+                        .compare( getNormalizedValueReference(), binaryValue.getNormalizedValueReference()
);
                 }
                 else
                 {
-                    return new ByteArrayComparator( null ).compare( getNormalizedValueReference(),

-                        binaryValue.getNormalizedValueReference() );
+                    return new ByteArrayComparator( null ).compare( getNormalizedValueReference(),
binaryValue
+                        .getNormalizedValueReference() );
                 }
             }
             catch ( NamingException e )
             {
-                String msg = "Failed to compare normalized values for " + Arrays.toString(
getReference() )
-                        + " and " + value;
+                String msg = "Failed to compare normalized values for " + Arrays.toString(
getReference() ) + " and "
+                    + value;
                 LOG.error( msg, e );
                 throw new IllegalStateException( msg, e );
             }
         }
 
-        String message = "I don't really know how to compare anything other " +
-        "than ServerBinaryValues at this point in time.";
+        String message = "I don't really know how to compare anything other "
+            + "than ServerBinaryValues at this point in time.";
         LOG.error( message );
         throw new NotImplementedException( message );
     }
@@ -463,18 +464,18 @@
             return true;
         }
 
-        if ( ! ( obj instanceof ServerBinaryValue ) )
+        if ( !( obj instanceof ServerBinaryValue ) )
         {
             return false;
         }
 
         ServerBinaryValue other = ( ServerBinaryValue ) obj;
-        
+
         if ( !attributeType.equals( other.attributeType ) )
         {
             return false;
         }
-        
+
         if ( isNull() )
         {
             return other.isNull();
@@ -578,21 +579,21 @@
 
         return mr.getLdapComparator();
     }
-    
-    
+
+
     /**
      * @return a copy of the current value
      */
     public ServerBinaryValue clone()
     {
-        ServerBinaryValue clone = (ServerBinaryValue)super.clone();
-        
+        ServerBinaryValue clone = ( ServerBinaryValue ) super.clone();
+
         if ( normalizedValue != null )
         {
-            clone.normalizedValue = new byte[ normalizedValue.length ];
+            clone.normalizedValue = new byte[normalizedValue.length];
             System.arraycopy( normalizedValue, 0, clone.normalizedValue, 0, normalizedValue.length
);
         }
-        
+
         return clone;
     }
 
@@ -602,13 +603,13 @@
      * 
      * We can't use this method for a ServerBinaryValue, as we have to feed the value
      * with an AttributeType object
-     */ 
+     */
     public void writeExternal( ObjectOutput out ) throws IOException
     {
         throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue"
);
     }
-    
-    
+
+
     /**
      * We will write the value and the normalized value, only
      * if the normalized value is different.
@@ -633,18 +634,18 @@
         {
             // write a the wrapped length
             out.writeInt( wrapped.length );
-            
+
             // Write the data if not empty
             if ( wrapped.length > 0 )
             {
                 // The data
                 out.write( wrapped );
-                
+
                 // Normalize the data
                 try
                 {
                     normalize();
-                    
+
                     if ( !normalized )
                     {
                         // We may not have a normalizer. Just get out
@@ -655,7 +656,7 @@
                     {
                         // Write a flag indicating that the data has been normalized
                         out.writeBoolean( true );
-                        
+
                         if ( Arrays.equals( getReference(), normalizedValue ) )
                         {
                             // Write the 'same = true' flag
@@ -665,10 +666,10 @@
                         {
                             // Write the 'same = false' flag
                             out.writeBoolean( false );
-                            
+
                             // Write the normalized value length
-                            out.write( normalizedValue.length );
-                            
+                            out.writeInt( normalizedValue.length );
+
                             if ( normalizedValue.length > 0 )
                             {
                                 // Write the normalized value if not empty
@@ -693,7 +694,7 @@
         }
     }
 
-    
+
     /**
      * @see Externalizable#readExternal(ObjectInput)
      * 
@@ -704,7 +705,7 @@
     {
         throw new IllegalStateException( "Cannot use standard serialization for a ServerStringValue"
);
     }
-    
+
 
     /**
      * 
@@ -718,7 +719,7 @@
     {
         // The UP value length
         int wrappedLength = in.readInt();
-        
+
         if ( wrappedLength == -1 )
         {
             // If the value is null, the length will be set to -1
@@ -727,35 +728,35 @@
         }
         else if ( wrappedLength == 0 )
         {
-             wrapped = StringTools.EMPTY_BYTES;
-             same = true;
-             normalized = true;
-             normalizedValue = wrapped;
+            wrapped = StringTools.EMPTY_BYTES;
+            same = true;
+            normalized = true;
+            normalizedValue = wrapped;
         }
         else
         {
             wrapped = new byte[wrappedLength];
-            
+
             // Read the data
             in.readFully( wrapped );
-            
+
             // Check if we have a normalized value
             normalized = in.readBoolean();
-            
+
             if ( normalized )
             {
                 // Read the 'same' flag
                 same = in.readBoolean();
-                
+
                 if ( !same )
                 {
                     // Read the normalizedvalue length
                     int normalizedLength = in.readInt();
-                
+
                     if ( normalizedLength > 0 )
                     {
                         normalizedValue = new byte[normalizedLength];
-                        
+
                         // Read the normalized value
                         in.read( normalizedValue, 0, normalizedLength );
                     }
@@ -772,4 +773,4 @@
             }
         }
     }
-}
+}



Mime
View raw message