You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/02/03 17:35:21 UTC

svn commit: r1240238 - /directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java

Author: elecharny
Date: Fri Feb  3 16:35:21 2012
New Revision: 1240238

URL: http://svn.apache.org/viewvc?rev=1240238&view=rev
Log:
Fixed the issue with Exif JPEG format not being accepeted. (DIRSERVER-1692)

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java?rev=1240238&r1=1240237&r2=1240238&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java Fri Feb  3 16:35:21 2012
@@ -6,16 +6,16 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.shared.ldap.model.schema.syntaxCheckers;
 
@@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
  * The JFIF (Jpeg File Interchange Format) specify that a jpeg image starts with
  * the following bytes :
  * 0xFF 0xD8 (SOI, Start Of Image)
- * 0xFF 0xE0 (App0)
+ * 0xFF 0xE0 (App0 for JFIF) or 0xDD 0xE1 (App1 for Exif)
  * 0xNN 0xNN (Header length)
  * "JFIF\0" (JFIF string with an ending \0)
  * some other bytes which are related to the image.
@@ -47,7 +47,6 @@ public class JpegSyntaxChecker extends S
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( JpegSyntaxChecker.class );
 
-
     /**
      * Creates a new instance of JpegSyntaxChecker.
      */
@@ -86,20 +85,34 @@ public class JpegSyntaxChecker extends S
 
         if ( ( bytes[0] == ( byte ) 0x00FF ) // SOI
             && ( bytes[1] == ( byte ) 0x00D8 )
-            && ( bytes[2] == ( byte ) 0x00FF ) // APP0
-            && ( bytes[3] == ( byte ) 0x00E0 )
-            && ( bytes[6] == 'J' ) // JFIF
-            && ( bytes[7] == 'F' ) // JFIF
-            && ( bytes[8] == 'I' ) // JFIF
-            && ( bytes[9] == 'F' )
-            && ( bytes[10] == 0x00 ) ) // \0
+            && ( bytes[2] == ( byte ) 0x00FF ) ) // APP0 or APP1
         {
-            // Note : this is not because the header is correct
-            // that the file is a jpeg file. There are much more
-            // elements to check, but we are not writing a jpeg
-            // file checker...
-            LOG.debug( "Syntax valid for '{}'", value );
-            return true;
+            if ( bytes[3] == (byte)0x00E0 )
+            {
+                // JFIF format
+                if ( ( bytes[6] == 'J' ) // JFIF
+                    && ( bytes[7] == 'F' ) // JFIF
+                    && ( bytes[8] == 'I' ) // JFIF
+                    && ( bytes[9] == 'F' )
+                    && ( bytes[10] == 0x00 ) ) // \0
+                {
+                    LOG.debug( "Syntax valid for '{}'", value );
+                    return true;
+                }
+            }
+            else if ( bytes[3] == (byte)0x00E1 )
+            {
+                // Exif format
+                if ( ( bytes[6] == 'E' )   // Exif
+                    && ( bytes[7] == 'x' ) // Exif
+                    && ( bytes[8] == 'i' ) // Exif
+                    && ( bytes[9] == 'f' ) // Exif
+                    && ( bytes[10] == 0x00 ) ) // \0
+                {
+                    LOG.debug( "Syntax valid for '{}'", value );
+                    return true;
+                }
+            }
         }
 
         LOG.debug( "Syntax invalid for '{}'", value );