Virtual Cocoaheads merged with Virtual NSCoders & Newly Discovered macOS Image Capture Bug Can Fill Up Hard Drives With Empty Data

4 views
Skip to the first unread message

David Phillip Oster

unread,
28 Apr 2020, 6:43:26 pm28/4/20
to CocoaHeads - Silicon Valley
For the last few weeks I've been attending the Tuesday 7pm to 9pm NSCoders meetup that normally meets at Orchard Cafe in Campbell, but during shelter in place, it is a Google Hangouts video conferencing . The hangouts URL is on the Meetup.com page: https://www.meetup.com/NSCoderNight-Silicon-Valley/events/bbxbslybcgblc/


https://www.macrumors.com/2020/04/28/macos-image-capture-bug-eats-storage/ published a story today on files read from iOS devices using ImageCapture have lots of zero padding.



I wrote a quick command line app to see if I had jgs with at least 500 bytes of trailing padding. I had 336, all since 2017.

Next step for me: since I have Tme Machine backups of this folder tree, is trimming back all such files to no more than 32 bytes of zero padding.

Here's the command line tool source code:

// Do I have any jpgs in my ~/Pictures or subdirectories such that they have more than 500 byts of trailing zero?

#import <Foundation/Foundation.h>


static BOOL HasEmptyTail(NSURL *url){

  NSData *data = [NSData dataWithContentsOfURL:url];

  if (501 < data.length) {

    uint8_t *p = (uint8_t *)data.bytes;

    p += data.length - 501;

    for (int i = 0; i < 500; ++i) {

      if (p[i]){

        return NO;

      }

    }

    return YES;

  }

  return NO;

}


static void TailZero() {

  NSFileManager *fm = [NSFileManager defaultManager];

  NSURL *url = [[fm URLsForDirectory:NSPicturesDirectory inDomains:NSUserDomainMaskfirstObject];

  NSArray<NSURL *> *items = [fm contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:0 error:NULL];

  for (NSURL *fileURL in items) {

    NSString *ext = [[fileURL pathExtensionlowercaseString];

    if ([ext isEqual:@"jpg"] || [ext isEqual:@"jpeg"]) {

      @autoreleasepool {

        if (HasEmptyTail(fileURL)) {

          fprintf(stderr"%s\n", fileURL.path.fileSystemRepresentation);

        }

      }

    }

  }

}


int main(int argc, const char * argv[]) {

  @autoreleasepool {

    TailZero();

  }

  return 0;

}


Reply all
Reply to author
Forward
0 new messages