Permalink
Browse files

Fix imgcat support for PDFs, which have no pixel size in their NSImag…

…eRep and need to create temp files in /private/var.
  • Loading branch information...
1 parent b04601f commit 16a331944c2d44da6f02406386ecfe141c371cb4 @gnachman committed Nov 15, 2016
Showing with 19 additions and 2 deletions.
  1. +8 −1 OtherResources/image_decoder.sb
  2. +11 −1 image_decoder/image_decoder.m
@@ -1,13 +1,20 @@
(version 1)
(deny default)
(allow file-read-data file-read-metadata
-(regex "^/System/Library/ColorSync/Profiles")
+ (regex "^/System/Library/ColorSync/Profiles")
(regex "^/System/Library/Frameworks")
(regex "^/System/Library/PrivateFrameworks")
(literal "/dev/null")
(literal "@PATH_TO_EXECUTABLE@")
(literal "@PATH_TO_EXECUTABLE@/@EXECUTABLE@")
+ (regex "^/private/var")
(regex "^/usr/lib"))
+(allow file-read-metadata
+ (regex "^/var$"))
+
+(allow file-write-create file-write-data file-write-unlink
+ (regex "^/private/var"))
+
(allow process-exec (literal "@PATH_TO_EXECUTABLE@/@EXECUTABLE@"))
(allow mach* sysctl-read)
@@ -53,7 +53,7 @@ int main(int argc, const char * argv[]) {
syslog(LOG_ERR, "Failed to read: %s", [[exception debugDescription] UTF8String]);
exit(1);
}
-
+
NSImage *image = [[NSImage alloc] initWithData:data];
if (!image) {
syslog(LOG_ERR, "data did not produce valid image");
@@ -65,6 +65,16 @@ int main(int argc, const char * argv[]) {
size_t count = CGImageSourceGetCount(source);
NSImageRep *rep = [[image representations] firstObject];
NSSize imageSize = NSMakeSize(rep.pixelsWide, rep.pixelsHigh);
+
+ if (imageSize.width == 0 && imageSize.height == 0) {
+ // PDFs can hit this case.
+ if (image.size.width != 0 && image.size.height != 0) {
+ imageSize = image.size;
+ } else {
+ syslog(LOG_ERR, "extracted image was 0x0");
+ exit(1);
+ }
+ }
serializableImage.size = imageSize;
if (count > 1) {

0 comments on commit 16a3319

Please sign in to comment.