QTMovie writeToFile: does not work in sandbox

Originator:chad515
Number:rdar://10644859 Date Originated:1/4/2012
Status:Closed Resolved:Yes
Product:Mac OS X Product Version:10.7.2
Classification:Serious Bug Reproducible:Always
 
Summary:
The writeToFile:withAttributes:error: method of QTMovie does not work when the app is sandboxed.

Steps to Reproduce:
A)
1) Create a sandboxed app that has a QTMovie movie object.
2) Open a NSSavePanel to get the file to save to (so that Powerbox will grant access to the path)
3) Call writeToFile:withAttributes:error: to write the file to the chosen path

B)
1) Create a sandboxed app that has a QTMovie movie object.
2) Create a path within the sandbox to write the file to
3) Call writeToFile:withAttributes:error: to write the file to the path within the sandbox

Expected Results:
The file is written successfully.

Actual Results:
The file is not written. The method fails and returns the error:
Error Domain=NSOSStatusErrorDomain Code=-54 "The operation couldn’t be completed. (OSStatus error -54.)" (permissions error (on file open))

Regression:
This method works fine if not sandboxed.

Notes:
This occurs regardless of whether the path being written to is allowed by Powerbox or within the sandbox itself. I presume that QTMovie is internally trying to write somewhere else while working and that is not allowed by the sandbox.

Interestingly, no sandbox denial shows up in the system log. It's as if something fishy is happening at the low level filesystem code in QTKit. I suspect its use of the Carbon File Manager is the culprit, given problems I've had before with it.

Comments

It's back

While this bug was fixed in 10.7.5 and throughout the life of 10.8, it is now back in 10.9. This can be seen here:

http://www.openradar.me/radar?id=6155582562107392

Fixed

This issue is fixed in 10.7.5 and 10.8 forward. I'm not sure why you were having problems in 10.8.1, as it worked for me.

SOLVED

Hi, sorry my english is poor.

The problem with QTMovie writetofile is in permissions to the internal process "create a file", the solution its easy. Just create a empty file after user click OK in savepanel, next call QTMovie writeToFile using the empty file name and problem is solved.

SAMPLE CODE

NSSavePanel *save = [NSSavePanel savePanel];
[save setAllowedFileTypes:[NSArray arrayWithObject:@"mov"]];
[save setAllowsOtherFileTypes:NO];

NSInteger result = [save runModal];
NSError *error = nil;
if (result == NSOKButton)
{
   //WRITE EMPTY FILE 
    NSString *EmptyFile = [[save URL] path];
    NSString *string = @"";

    [string writeToFile:EmptyFile
             atomically:NO
               encoding:NSUTF8StringEncoding
                  error:&error];

    //WRITE MOVIE FILE
    NSString *selectedFile = [[save URL] path];
    NSDictionary *attributen = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithBool:YES], QTMovieFlatten,
                                [NSNumber numberWithBool:YES], QTMovieExport,
                                [NSNumber numberWithInt:kQTFileTypeMP4], QTMovieExportType,
                                nil];
    [QTMovie enterQTKitOnThread];
    [mMovie attachToCurrentThread];
    //BOOL TO WRITETOFILE
    BOOL result = [mMovie writeToFile: selectedFile withAttributes:attributen error:&error];

    //ERROR CONTROL
    if (error) {
        NSLog(@"Fail: %@", [error localizedDescription]);
        [NSApp presentError:error];
    }
    //RESULT CONTROL
    if (!result) {
        [mMovie detachFromCurrentThread];
        [QTMovie exitQTKitOnThread];
        NSLog(@"FAIL");
        //If you need Remove EmptyFile 
    } else{
        [mMovie detachFromCurrentThread];
        [QTMovie exitQTKitOnThread];
        NSLog(@"OK");
    }
}
By diariodeunpescado at Oct. 15, 2012, 3:09 p.m. (reply...)

Update as of 10.8.1

This issue is still not yet fixed in 10.8.1

By sasmito.adibowo at Sept. 1, 2012, 7:03 p.m. (reply...)

Update as of 10.7.4

This issue is still prevalent in 10.7.4. Tested on 8/13/2012


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!