[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:11:56 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 5d390593c637c92089b96637ae57a799a4e57f79
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Dec 6 00:31:35 2002 +0000

    WebFoundation:
    
            Reviewed by Chris.
    
            * English.lproj/StringsNotToBeLocalized.txt: Updated for recent changes.
    
    WebKit:
    
            Reviewed by Chris.
    
            * Downloads.subproj/WebDownloadHandler.m: (-[WebDownloadHandler initWithDataSource:]):
    	Add WebGZipDecoder to the list.
    
            * Downloads.subproj/WebGZipDecoder.h: Finished this.
            * Downloads.subproj/WebGZipDecoder.m: Finished this.
    
            * English.lproj/StringsNotToBeLocalized.txt: Updated for recent changes.
    
    WebBrowser:
    
            Reviewed by Chris.
    
            * BugReportController.m: Removed obsolete FIXME.
    
            * English.lproj/StringsNotToBeLocalized.txt: Updated for recent changes.
            * English.lproj/Localizable.strings: Regenerated this, some string somewhere changed.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2950 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index a46cdae..7601eb8 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,15 @@
+2002-12-05  Darin Adler  <darin at apple.com>
+
+        Reviewed by Chris.
+
+        * Downloads.subproj/WebDownloadHandler.m: (-[WebDownloadHandler initWithDataSource:]):
+	Add WebGZipDecoder to the list.
+
+        * Downloads.subproj/WebGZipDecoder.h: Finished this.
+        * Downloads.subproj/WebGZipDecoder.m: Finished this.
+
+        * English.lproj/StringsNotToBeLocalized.txt: Updated for recent changes.
+
 2002-12-05  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by: Darin
diff --git a/WebKit/Downloads.subproj/WebDownload.m b/WebKit/Downloads.subproj/WebDownload.m
index bc5181c..1bb914a 100644
--- a/WebKit/Downloads.subproj/WebDownload.m
+++ b/WebKit/Downloads.subproj/WebDownload.m
@@ -11,6 +11,7 @@
 #import <WebKit/WebBinHexDecoder.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDownloadDecoder.h>
+#import <WebKit/WebGZipDecoder.h>
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebMacBinaryDecoder.h>
@@ -30,6 +31,7 @@
     decoderClasses = [[NSArray arrayWithObjects:
         [WebBinHexDecoder class],
         [WebMacBinaryDecoder class],
+        [WebGZipDecoder class],
         nil] retain];
     
     LOG(Download, "Download started for: %@", [[dSource request] URL]);
diff --git a/WebKit/Downloads.subproj/WebDownloadHandler.m b/WebKit/Downloads.subproj/WebDownloadHandler.m
index bc5181c..1bb914a 100644
--- a/WebKit/Downloads.subproj/WebDownloadHandler.m
+++ b/WebKit/Downloads.subproj/WebDownloadHandler.m
@@ -11,6 +11,7 @@
 #import <WebKit/WebBinHexDecoder.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDownloadDecoder.h>
+#import <WebKit/WebGZipDecoder.h>
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebMacBinaryDecoder.h>
@@ -30,6 +31,7 @@
     decoderClasses = [[NSArray arrayWithObjects:
         [WebBinHexDecoder class],
         [WebMacBinaryDecoder class],
+        [WebGZipDecoder class],
         nil] retain];
     
     LOG(Download, "Download started for: %@", [[dSource request] URL]);
diff --git a/WebKit/Downloads.subproj/WebGZipDecoder.h b/WebKit/Downloads.subproj/WebGZipDecoder.h
index eec613c..8841ca1 100644
--- a/WebKit/Downloads.subproj/WebGZipDecoder.h
+++ b/WebKit/Downloads.subproj/WebGZipDecoder.h
@@ -16,7 +16,17 @@
 {
     z_stream _stream;
     BOOL _streamInitialized;
+
+    BOOL _decodedHeader;
+    unsigned _modificationTime;
+    NSString *_filename;
+    
+    unsigned _size;
+    unsigned _CRC32;
+    
+    BOOL _finishedInflating;
     
-    BOOL _failed;
+    unsigned char _trailingBytes[8];
+    int _trailingBytesLength;
 }
 @end
diff --git a/WebKit/Downloads.subproj/WebGZipDecoder.m b/WebKit/Downloads.subproj/WebGZipDecoder.m
index 9f9a672..ffd0b2b 100644
--- a/WebKit/Downloads.subproj/WebGZipDecoder.m
+++ b/WebKit/Downloads.subproj/WebGZipDecoder.m
@@ -11,21 +11,110 @@
 #import <WebFoundation/WebAssertions.h>
 #import <WebKit/WebDownloadDecoder.h>
 
+#define ID1 0x1F
+#define ID2 0x8B
+#define DEFLATE_COMPRESSION_METHOD 8
+
+#define FTEXT 0x01
+#define FHCRC 0x02
+#define FEXTRA 0x04
+#define FNAME 0x08
+#define FCOMMENT 0x10
+#define RESERVED_FLAGS 0xE0
+
 @implementation WebGZipDecoder
 
-+ (BOOL)canDecodeHeaderData:(NSData *)headerData
++ (BOOL)decodeHeader:(NSData *)headerData headerLength:(int *)headerLength modificationTime:(unsigned *)modificationTime filename:(NSString **)filename
 {
-    if ([headerData length] < 2) {
+    int headerDataLength = [headerData length];
+    int length = 10;
+    
+    if (headerDataLength < length) {
         return NO;
     }
+    
     const unsigned char *bytes = (const unsigned char *)[headerData bytes];
-    return (bytes[0] == 0x1F) && (bytes[1] == 0x8B) && 0;
+    
+    if (bytes[0] != ID1 || bytes[1] != ID2) {
+        return NO;
+    }
+    
+    if (bytes[2] != DEFLATE_COMPRESSION_METHOD) {
+        return NO;
+    }
+    
+    unsigned char flags = bytes[3];
+    if (flags & RESERVED_FLAGS) {
+        return NO;
+    }
+    
+    if (flags & FEXTRA) {
+        if (headerDataLength < length + 2) {
+            return NO;
+        }
+        length += 2 + (bytes[10] | (bytes[11] << 8));
+        if (headerDataLength < length) {
+            return NO;
+        }
+    }
+    
+    const char *filenameCString = 0;
+    if (flags & FNAME) {
+        filenameCString = (const char *)&bytes[length];
+        while (bytes[length++] != 0) {
+            if (headerDataLength < length) {
+                return NO;
+            }
+        }
+    } else {
+        // The decoder framework won't handle files without filenames well.
+        return NO;
+    }
+    
+    if (flags & FCOMMENT) {
+        while (bytes[length++] != 0) {
+            if (headerDataLength < length) {
+                return NO;
+            }
+        }
+    }
+    
+    if (flags & FHCRC) {
+        if (headerDataLength < length + 2) {
+            return NO;
+        }
+        unsigned computedCRC = crc32(0, bytes, length) & 0xFFFF;
+        unsigned expectedCRC = bytes[length] + bytes[length + 1];
+        if (computedCRC != expectedCRC) {
+            return NO;
+        }
+        length += 2;
+    }
+    
+    if (headerLength) {
+        *headerLength = length;
+    }
+    
+    if (modificationTime) {
+        *modificationTime = bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24);
+    }
+    
+    if (filename) {
+        *filename = [(NSString *)CFStringCreateWithCString(NULL, filenameCString, kCFStringEncodingWindowsLatin1) autorelease];
+    }
+    
+    return YES;
+}
+
++ (BOOL)canDecodeHeaderData:(NSData *)headerData
+{
+    return [self decodeHeader:headerData headerLength:NULL modificationTime:NULL filename:NULL];
 }
 
 - (id)init
 {
     self = [super init];
-    int error = inflateInit(&_stream);
+    int error = inflateInit2(&_stream, -15); // window of 15 is standard for gzip, negative number is secret zlib feature to avoid processing header
     if (error != Z_OK) {
         ERROR("failed to initialize zlib, error %d", error);
         [self release];
@@ -39,6 +128,7 @@
 {
     if (_streamInitialized)
         inflateEnd(&_stream);
+    [_filename release];
     [super dealloc];
 }
 
@@ -48,14 +138,86 @@
     ASSERT([data length]);
     ASSERT(dataForkData);
     ASSERT(resourceForkData);
+    ASSERT(_streamInitialized);
     
     *dataForkData = nil;
     *resourceForkData = nil;
     
-    int error = inflate(&_stream, Z_NO_FLUSH);
-    if (error != Z_OK) {
-        _failed = YES;
-        return NO;
+    int offset = 0;
+
+    // Decode the header.
+    if (!_decodedHeader) {
+        NSString *filename;
+        if (![[self class] decodeHeader:data
+                           headerLength:&offset
+                       modificationTime:&_modificationTime
+                               filename:&filename]) {
+            return NO;
+        }
+        
+        ASSERT(!_filename);
+        _filename = [filename copy];
+        
+        _decodedHeader = YES;
+    }
+    
+    // Decode the compressed data.
+    if (!_finishedInflating) {
+        NSMutableData *inflatedData = [NSMutableData data];
+        *dataForkData = inflatedData;
+        
+        _stream.next_in = (char *)[data bytes] + offset;
+        _stream.avail_in = [data length] - offset;
+        
+        while (_stream.avail_in) {
+            char outputBuffer[16384];
+        
+            _stream.next_out = outputBuffer;
+            _stream.avail_out = sizeof(outputBuffer);
+        
+            int result = inflate(&_stream, Z_NO_FLUSH);
+            
+            int outputLength = sizeof(outputBuffer) - _stream.avail_out;
+            _size += outputLength;
+            _CRC32 = crc32(_CRC32, outputBuffer, outputLength);
+            [inflatedData appendBytes:outputBuffer length:outputLength];
+        
+            if (result == Z_STREAM_END) {
+                _finishedInflating = YES;
+                break;
+            }
+        
+            if (result != Z_OK) {
+                ERROR("got error from inflate, %d", result);
+                return NO;
+            }
+        }
+        
+        offset = [data length] - _stream.avail_in;
+    }
+    
+    // Decode the trailer.
+    if (_finishedInflating && _trailingBytesLength < 8) {
+        int numRemaining = [data length] - offset;
+        if (numRemaining) {
+            int numToCopy = MIN(numRemaining, 8 - _trailingBytesLength);
+            memcpy(_trailingBytes + _trailingBytesLength, (char *)[data bytes] + offset, numToCopy);
+            _trailingBytesLength += numToCopy;
+            if (_trailingBytesLength == 8) {
+                unsigned expectedCRC = _trailingBytes[0] | (_trailingBytes[1] << 8)
+                    | (_trailingBytes[2] << 16) | (_trailingBytes[3] << 24);
+                if (_CRC32 != expectedCRC) {
+                    ERROR("CRC didn't match, computed %08X, expected %08X", _CRC32, expectedCRC);
+                    return NO;
+                }
+                unsigned expectedSize = _trailingBytes[4] | (_trailingBytes[5] << 8)
+                    | (_trailingBytes[6] << 16) | (_trailingBytes[7] << 24);
+                if (_size != expectedSize) {
+                    ERROR("size didn't match, computed %d, expected %d", _size, expectedSize);
+                    return NO;
+                }
+            }
+        }
     }
 
     return YES;
@@ -63,22 +225,24 @@
 
 - (BOOL)finishDecoding
 {
-    int error = inflate(&_stream, Z_FINISH);
-    if (error != Z_OK) {
-        _failed = YES;
-        return NO;
-    }
-    return YES;
+    ASSERT(_streamInitialized);
+    return _finishedInflating && _trailingBytesLength == 8;
 }
 
 - (NSDictionary *)fileAttributes
 {
-    return nil;
+    ASSERT(_decodedHeader);
+    if (_modificationTime == 0) {
+        return nil;
+    }
+    return [NSDictionary dictionaryWithObject:[NSDate dateWithTimeIntervalSinceReferenceDate:NSTimeIntervalSince1970 + _modificationTime]
+                                       forKey:NSFileModificationDate];
 }
 
 - (NSString *)filename
 {
-    return nil;
+    ASSERT(_decodedHeader);
+    return [[_filename copy] autorelease];
 }
 
 @end
diff --git a/WebKit/English.lproj/StringsNotToBeLocalized.txt b/WebKit/English.lproj/StringsNotToBeLocalized.txt
index 38f41a5..69e1dbf 100644
--- a/WebKit/English.lproj/StringsNotToBeLocalized.txt
+++ b/WebKit/English.lproj/StringsNotToBeLocalized.txt
@@ -18,6 +18,7 @@
 "/tmp/%@"
 "0x0"
 "1.00"
+"10"
 "1000"
 "14"
 "4096"
@@ -154,6 +155,7 @@
 "WebKitJavaScriptEnabled"
 "WebKitLogLevel"
 "WebKitMinimumFontSize"
+"WebKitPageCacheSizePreferenceKey"
 "WebKitPluginsEnabled"
 "WebKitResourceTimedLayoutDelay"
 "WebKitResourceTimedLayoutEnabled"

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list