Images shared to photos via action menu are padded with zeroes at the end
[WebKit-https.git] / Source / WebKit2 / UIProcess / mac / WKActionMenuController.mm
index c0a554d4d6b9f097bcc0ea3ea25c35630dc4d157..fd7ec5a6111eb2493758f761569b7793bb42c025 100644 (file)
@@ -245,7 +245,7 @@ using namespace WebKit;
     if (!imageSharedMemory)
         return nil;
 
-    RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]]);
+    RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:imageSharedMemory->data() length:_hitTestResult.imageSize]]);
     return nsImage.autorelease();
 }
 
@@ -335,10 +335,10 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
         return;
 
     RefPtr<SharedMemory> imageSharedMemory = _hitTestResult.imageSharedMemory;
-    if (!imageSharedMemory->size() || _hitTestResult.imageExtension.isEmpty())
+    if (!imageSharedMemory->data() || _hitTestResult.imageExtension.isEmpty() || !_hitTestResult.imageSize)
         return;
 
-    RetainPtr<NSData> imageData = adoptNS([[NSData alloc] initWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]);
+    RetainPtr<NSData> imageData = adoptNS([[NSData alloc] initWithBytes:imageSharedMemory->data() length:_hitTestResult.imageSize]);
     RetainPtr<NSString> suggestedFilename = [[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:_hitTestResult.imageExtension];
 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{