Core data binary data with allows external storage crashes












0














I have a crash with the following log on iOS 12.0.1:



ImageIO: CFDataGetBytes: data: 0x28539b2f0 size: 154262 offset: 8 count: 8 dst: 0x16dbf86f0
External data reference cant find underlying file.
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x23c2d7ef8 __exceptionPreprocess
1 libobjc.A.dylib 0x23b4a5a40 objc_exception_throw
2 CoreData 0x23efd5fc8 -[_PFExternalReferenceData getBytes:range:]
3 ImageIO 0x23e6c7178 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long)
4 ImageIO 0x23e6c6c38 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long)
5 ImageIO 0x23e711aa4 IIO_Reader_PNG::getImageCount(IIOImageReadSession*, IIODictionary*, int*, unsigned int*)
6 ImageIO 0x23e54c5d8 IIO_Reader::callGetImageCount(CGImageReadSession*, IIODictionary*, int*)
7 ImageIO 0x23e532194 IIOImageSource::updatedCount()
8 ImageIO 0x23e5367b4 CGImageSourceGetCount
9 UIKitCore 0x26960c1a4 _UIImageRefFromData
10 UIKitCore 0x268d4e15c -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:]
11 UIKitCore 0x268d48b7c +[UIImage imageWithData:]
12 MyApp 0x102239570 __48-[InfoPreviewController bindToPatient:]_block_invoke_2 (InfoPreviewController.m:83)
13 ReactiveObjC 0x1031f8004 -[RACSubscriber sendNext:] (RACSubscriber.m:72)


enter image description here



It seems that core data has the image, but when it tries to retrieve it, it fails.



How can I verify the data integrity in this case?
I would like to handle this failure in a user friendly way instead of crashing the app.










share|improve this question





























    0














    I have a crash with the following log on iOS 12.0.1:



    ImageIO: CFDataGetBytes: data: 0x28539b2f0 size: 154262 offset: 8 count: 8 dst: 0x16dbf86f0
    External data reference cant find underlying file.
    Fatal Exception: NSInternalInconsistencyException
    0 CoreFoundation 0x23c2d7ef8 __exceptionPreprocess
    1 libobjc.A.dylib 0x23b4a5a40 objc_exception_throw
    2 CoreData 0x23efd5fc8 -[_PFExternalReferenceData getBytes:range:]
    3 ImageIO 0x23e6c7178 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long)
    4 ImageIO 0x23e6c6c38 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long)
    5 ImageIO 0x23e711aa4 IIO_Reader_PNG::getImageCount(IIOImageReadSession*, IIODictionary*, int*, unsigned int*)
    6 ImageIO 0x23e54c5d8 IIO_Reader::callGetImageCount(CGImageReadSession*, IIODictionary*, int*)
    7 ImageIO 0x23e532194 IIOImageSource::updatedCount()
    8 ImageIO 0x23e5367b4 CGImageSourceGetCount
    9 UIKitCore 0x26960c1a4 _UIImageRefFromData
    10 UIKitCore 0x268d4e15c -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:]
    11 UIKitCore 0x268d48b7c +[UIImage imageWithData:]
    12 MyApp 0x102239570 __48-[InfoPreviewController bindToPatient:]_block_invoke_2 (InfoPreviewController.m:83)
    13 ReactiveObjC 0x1031f8004 -[RACSubscriber sendNext:] (RACSubscriber.m:72)


    enter image description here



    It seems that core data has the image, but when it tries to retrieve it, it fails.



    How can I verify the data integrity in this case?
    I would like to handle this failure in a user friendly way instead of crashing the app.










    share|improve this question



























      0












      0








      0







      I have a crash with the following log on iOS 12.0.1:



      ImageIO: CFDataGetBytes: data: 0x28539b2f0 size: 154262 offset: 8 count: 8 dst: 0x16dbf86f0
      External data reference cant find underlying file.
      Fatal Exception: NSInternalInconsistencyException
      0 CoreFoundation 0x23c2d7ef8 __exceptionPreprocess
      1 libobjc.A.dylib 0x23b4a5a40 objc_exception_throw
      2 CoreData 0x23efd5fc8 -[_PFExternalReferenceData getBytes:range:]
      3 ImageIO 0x23e6c7178 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long)
      4 ImageIO 0x23e6c6c38 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long)
      5 ImageIO 0x23e711aa4 IIO_Reader_PNG::getImageCount(IIOImageReadSession*, IIODictionary*, int*, unsigned int*)
      6 ImageIO 0x23e54c5d8 IIO_Reader::callGetImageCount(CGImageReadSession*, IIODictionary*, int*)
      7 ImageIO 0x23e532194 IIOImageSource::updatedCount()
      8 ImageIO 0x23e5367b4 CGImageSourceGetCount
      9 UIKitCore 0x26960c1a4 _UIImageRefFromData
      10 UIKitCore 0x268d4e15c -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:]
      11 UIKitCore 0x268d48b7c +[UIImage imageWithData:]
      12 MyApp 0x102239570 __48-[InfoPreviewController bindToPatient:]_block_invoke_2 (InfoPreviewController.m:83)
      13 ReactiveObjC 0x1031f8004 -[RACSubscriber sendNext:] (RACSubscriber.m:72)


      enter image description here



      It seems that core data has the image, but when it tries to retrieve it, it fails.



      How can I verify the data integrity in this case?
      I would like to handle this failure in a user friendly way instead of crashing the app.










      share|improve this question















      I have a crash with the following log on iOS 12.0.1:



      ImageIO: CFDataGetBytes: data: 0x28539b2f0 size: 154262 offset: 8 count: 8 dst: 0x16dbf86f0
      External data reference cant find underlying file.
      Fatal Exception: NSInternalInconsistencyException
      0 CoreFoundation 0x23c2d7ef8 __exceptionPreprocess
      1 libobjc.A.dylib 0x23b4a5a40 objc_exception_throw
      2 CoreData 0x23efd5fc8 -[_PFExternalReferenceData getBytes:range:]
      3 ImageIO 0x23e6c7178 IIOImageRead::getCFDataBytesAtOffset(void*, unsigned long, unsigned long)
      4 ImageIO 0x23e6c6c38 IIOImageRead::getBytesAtOffset(void*, unsigned long, unsigned long)
      5 ImageIO 0x23e711aa4 IIO_Reader_PNG::getImageCount(IIOImageReadSession*, IIODictionary*, int*, unsigned int*)
      6 ImageIO 0x23e54c5d8 IIO_Reader::callGetImageCount(CGImageReadSession*, IIODictionary*, int*)
      7 ImageIO 0x23e532194 IIOImageSource::updatedCount()
      8 ImageIO 0x23e5367b4 CGImageSourceGetCount
      9 UIKitCore 0x26960c1a4 _UIImageRefFromData
      10 UIKitCore 0x268d4e15c -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:]
      11 UIKitCore 0x268d48b7c +[UIImage imageWithData:]
      12 MyApp 0x102239570 __48-[InfoPreviewController bindToPatient:]_block_invoke_2 (InfoPreviewController.m:83)
      13 ReactiveObjC 0x1031f8004 -[RACSubscriber sendNext:] (RACSubscriber.m:72)


      enter image description here



      It seems that core data has the image, but when it tries to retrieve it, it fails.



      How can I verify the data integrity in this case?
      I would like to handle this failure in a user friendly way instead of crashing the app.







      ios objective-c core-data






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 16:34

























      asked Nov 14 '18 at 13:03









      Zsolt

      2,12732443




      2,12732443
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This is caused by a known bug in Core Data external storage in iOS 12.0.x as discussed here: https://stackoverflow.com/a/52628198/2347353. There is no workaround, but the bug appears to be fixed in iOS 12.1.



          To answer your question though, with a bit of hackery-pokery, you can get the filename where the data is supposed to be stored and check to see if it exists or not. If the file is missing, then you know that the corruption has happened so you can avoid reading the attribute, and therefore prevent the app from crashing.



          None of this is documented, but the files seem to be stored in the _EXTERNAL_DATA hidden directory in your app’s Documents folder with a filename that you can work out from a value that is saved to the data store.



          This answer shows how to do this in Objective-C and is where I got a lot of the details from: https://stackoverflow.com/a/13497992/2347353. But for anyone trying this at home, please do heed the warnings that this is all based on Apple’s internal implementation details of Core Data and could stop working at any point in the future.






          share|improve this answer





















          • thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
            – Zsolt
            Nov 15 '18 at 10:12










          • update: I just got this crash on iOS 12.1.0
            – Zsolt
            Nov 19 '18 at 9:22










          • do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
            – Zsolt
            Nov 20 '18 at 12:56











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300900%2fcore-data-binary-data-with-allows-external-storage-crashes%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This is caused by a known bug in Core Data external storage in iOS 12.0.x as discussed here: https://stackoverflow.com/a/52628198/2347353. There is no workaround, but the bug appears to be fixed in iOS 12.1.



          To answer your question though, with a bit of hackery-pokery, you can get the filename where the data is supposed to be stored and check to see if it exists or not. If the file is missing, then you know that the corruption has happened so you can avoid reading the attribute, and therefore prevent the app from crashing.



          None of this is documented, but the files seem to be stored in the _EXTERNAL_DATA hidden directory in your app’s Documents folder with a filename that you can work out from a value that is saved to the data store.



          This answer shows how to do this in Objective-C and is where I got a lot of the details from: https://stackoverflow.com/a/13497992/2347353. But for anyone trying this at home, please do heed the warnings that this is all based on Apple’s internal implementation details of Core Data and could stop working at any point in the future.






          share|improve this answer





















          • thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
            – Zsolt
            Nov 15 '18 at 10:12










          • update: I just got this crash on iOS 12.1.0
            – Zsolt
            Nov 19 '18 at 9:22










          • do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
            – Zsolt
            Nov 20 '18 at 12:56
















          0














          This is caused by a known bug in Core Data external storage in iOS 12.0.x as discussed here: https://stackoverflow.com/a/52628198/2347353. There is no workaround, but the bug appears to be fixed in iOS 12.1.



          To answer your question though, with a bit of hackery-pokery, you can get the filename where the data is supposed to be stored and check to see if it exists or not. If the file is missing, then you know that the corruption has happened so you can avoid reading the attribute, and therefore prevent the app from crashing.



          None of this is documented, but the files seem to be stored in the _EXTERNAL_DATA hidden directory in your app’s Documents folder with a filename that you can work out from a value that is saved to the data store.



          This answer shows how to do this in Objective-C and is where I got a lot of the details from: https://stackoverflow.com/a/13497992/2347353. But for anyone trying this at home, please do heed the warnings that this is all based on Apple’s internal implementation details of Core Data and could stop working at any point in the future.






          share|improve this answer





















          • thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
            – Zsolt
            Nov 15 '18 at 10:12










          • update: I just got this crash on iOS 12.1.0
            – Zsolt
            Nov 19 '18 at 9:22










          • do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
            – Zsolt
            Nov 20 '18 at 12:56














          0












          0








          0






          This is caused by a known bug in Core Data external storage in iOS 12.0.x as discussed here: https://stackoverflow.com/a/52628198/2347353. There is no workaround, but the bug appears to be fixed in iOS 12.1.



          To answer your question though, with a bit of hackery-pokery, you can get the filename where the data is supposed to be stored and check to see if it exists or not. If the file is missing, then you know that the corruption has happened so you can avoid reading the attribute, and therefore prevent the app from crashing.



          None of this is documented, but the files seem to be stored in the _EXTERNAL_DATA hidden directory in your app’s Documents folder with a filename that you can work out from a value that is saved to the data store.



          This answer shows how to do this in Objective-C and is where I got a lot of the details from: https://stackoverflow.com/a/13497992/2347353. But for anyone trying this at home, please do heed the warnings that this is all based on Apple’s internal implementation details of Core Data and could stop working at any point in the future.






          share|improve this answer












          This is caused by a known bug in Core Data external storage in iOS 12.0.x as discussed here: https://stackoverflow.com/a/52628198/2347353. There is no workaround, but the bug appears to be fixed in iOS 12.1.



          To answer your question though, with a bit of hackery-pokery, you can get the filename where the data is supposed to be stored and check to see if it exists or not. If the file is missing, then you know that the corruption has happened so you can avoid reading the attribute, and therefore prevent the app from crashing.



          None of this is documented, but the files seem to be stored in the _EXTERNAL_DATA hidden directory in your app’s Documents folder with a filename that you can work out from a value that is saved to the data store.



          This answer shows how to do this in Objective-C and is where I got a lot of the details from: https://stackoverflow.com/a/13497992/2347353. But for anyone trying this at home, please do heed the warnings that this is all based on Apple’s internal implementation details of Core Data and could stop working at any point in the future.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 22:23









          rodhan

          1666




          1666












          • thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
            – Zsolt
            Nov 15 '18 at 10:12










          • update: I just got this crash on iOS 12.1.0
            – Zsolt
            Nov 19 '18 at 9:22










          • do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
            – Zsolt
            Nov 20 '18 at 12:56


















          • thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
            – Zsolt
            Nov 15 '18 at 10:12










          • update: I just got this crash on iOS 12.1.0
            – Zsolt
            Nov 19 '18 at 9:22










          • do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
            – Zsolt
            Nov 20 '18 at 12:56
















          thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
          – Zsolt
          Nov 15 '18 at 10:12




          thanks @rodhan. I want to point out that the path has changed from Documents to Library/projectname (iOS12). Indeed very hacky.
          – Zsolt
          Nov 15 '18 at 10:12












          update: I just got this crash on iOS 12.1.0
          – Zsolt
          Nov 19 '18 at 9:22




          update: I just got this crash on iOS 12.1.0
          – Zsolt
          Nov 19 '18 at 9:22












          do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
          – Zsolt
          Nov 20 '18 at 12:56




          do you by any chance know how to force core data to make use of the Allow External Storage for testing? I tried adding a large image in the hope that core data logic will kick in and moves the file to external storage, but it does not seem to be the case.
          – Zsolt
          Nov 20 '18 at 12:56


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300900%2fcore-data-binary-data-with-allows-external-storage-crashes%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)