copyfile(src, dest, NULL, COPYFILE_UNPACK) only handles very limited subset of AppleDouble files
| Originator: | nbeadman | ||
| Number: | rdar://20966567 | Date Originated: | 14-May-2015 |
| Status: | Open | Resolved: | |
| Product: | OS X SDK | Product Version: | 10.10.3 (14D136) |
| Classification: | Data Loss | Reproducible: | Always |
Summary: Trying to use copyfile() to combine an AppleDouble file and a data fork file into a single file only works if the AppleDouble table of contents contains two entries and the first entry must be AD_FINDERINFO (= 9) Steps to Reproduce: Open the attached Xcode project and build and run. This will attempt to combine the copyfile.jpg.AppleDouble and copyfile.jpg.DataFork in to copyfile.jpg. You will see that copyfile(src, dest, NULL, COPYFILE_UNPACK) will fail with -1. Unfortunately, errno is not set so will not a valid value. The supplied copyfile.jpg.AppleDouble is valid it just has a AD_FILEDATES (=8) entry as well as the Finder Info and AD_RESOURCE (=2) entries I worked around by rewriting the Apple Double TOC to contain just the two expected entries and leaving gaps in the file (so just setting number of entries to 2 and the offsets correct for Finder Info and resource). Expected Results: A valid copyfile.jpg is produced. You can see this outcome by replacing copyfile.jpg.AppleDoube from testfiles/originals/succeeds to testfiles and running again. Actual Results: copyfile returns -1 but errno is not set. Version: Xcode 6.3/6D570 tested with 10.10 SDK OS X 10.10.3 (14D136) copyfile-118.1.2 Notes: copyfile() appears to be in iOS too and has the same implementation and therefore bug. I figured everything out using the implementation at <http://www.opensource.apple.com/source/copyfile/copyfile-118.1.2/> If you just ignore Apple Double TOC entries other than Finder Info and resource fork this is probably an easy enough fix. Looking back through the implementations of copyfile() it appears that this has been an issue for some time (maybe since the beginning). Configuration: Occurs in all configurations where the AppleDouble file is not in the format expected. Sample project: <https://dl.dropboxusercontent.com/u/56582/copyfile-radar-20966567.zip>
Comments
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!