[GH-ISSUE #118] [BUG] Guest Apps Cannot Access tmp folder created by .itemReplacementDirectory #106

Closed
opened 2026-03-03 15:30:36 +03:00 by kerem · 9 comments
Owner

Originally created by @hugeBlack on GitHub (Aug 12, 2024).
Original GitHub issue: https://github.com/LiveContainer/LiveContainer/issues/118

Describe the bug

When I was trying to address with issue #82 , where the Aidoku app can't add manga sources. It turns out that the app attempted to create a temporary folder to store decompressed files. However, it used the following code to create it:

let tmpFolder = try? url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: documentDirectory, create: true)

Here's the original code

It appears that this code created the folder in file:///private/var/mobile/Containers/Data/Application/D4F742C8-E9AE-4D06-B00E-3CB37D11E767/tmp//C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491/tmp/NSIRD_Aidoku_LfvIwr/, which is the tmp folder of liveContainer itself,

where D4F742C8-E9AE-4D06-B00E-3CB37D11E767 is the uuid of LiveContainer, and the app can't write to it, thus failing to add source. Changing the .itemReplacementDirectory into .documentDirectory addressed this issue

Instructions to reproduce

Write a program that tries to create a temporary folder with the said method and try to write to that temp folder.

What version of LiveContainer are you using?

2.2.1-release

Other info

I believe that there are many apps use this method to create temporary folders since Apple includes this method in their document. Addressing this issue will surly contribute to LiveContainer's compatibility.

Originally created by @hugeBlack on GitHub (Aug 12, 2024). Original GitHub issue: https://github.com/LiveContainer/LiveContainer/issues/118 ### Describe the bug When I was trying to address with issue #82 , where the Aidoku app can't add manga sources. It turns out that the app attempted to create a temporary folder to store decompressed files. However, it used the following code to create it: ```swift let tmpFolder = try? url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: documentDirectory, create: true) ``` [Here's the original code](https://github.com/Aidoku/Aidoku/blob/588a4acc42245ddd9832b2cadd1e7f1d73b45b6e/Shared/Extensions/FileManager.swift#L64) It appears that this code created the folder in `file:///private/var/mobile/Containers/Data/Application/D4F742C8-E9AE-4D06-B00E-3CB37D11E767/tmp//C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491/tmp/NSIRD_Aidoku_LfvIwr/`, which is the tmp folder of liveContainer itself, where `D4F742C8-E9AE-4D06-B00E-3CB37D11E767` is the uuid of LiveContainer, and the app can't write to it, thus failing to add source. Changing the `.itemReplacementDirectory` into `.documentDirectory` addressed this issue ### Instructions to reproduce Write a program that tries to create a temporary folder with the said method and try to write to that temp folder. ### What version of LiveContainer are you using? 2.2.1-release ### Other info I believe that there are many apps use this method to create temporary folders since Apple includes this method in their document. Addressing this issue will surly contribute to LiveContainer's compatibility.
kerem 2026-03-03 15:30:36 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@khanhduytran0 commented on GitHub (Aug 13, 2024):

where D4F742C8-E9AE-4D06-B00E-3CB37D11E767 is the uuid of LiveContainer, and the app can't write to it, thus failing to add source

Hmm, it’s weird, considering I have already stated this (also applies to tmp):

Guest app containers are not sandboxed. This means one guest app can access other guest apps' data.

I made the decision to redirect all tmp files to LiveContainer’s tmp since it would be properly cleaned up by iOS. I’ll try other ways and let you know

<!-- gh-comment-id:2285635138 --> @khanhduytran0 commented on GitHub (Aug 13, 2024): > where D4F742C8-E9AE-4D06-B00E-3CB37D11E767 is the uuid of LiveContainer, and the app can't write to it, thus failing to add source Hmm, it’s weird, considering I have already stated this (also applies to tmp): > Guest app containers are not sandboxed. This means one guest app can access other guest apps' data. I made the decision to redirect all tmp files to LiveContainer’s tmp since it would be properly cleaned up by iOS. I’ll try other ways and let you know
Author
Owner

@khanhduytran0 commented on GitHub (Aug 13, 2024):

Well, the issue boils down to the extraneous slash in tmp path

tmp//C0BB21DC
   ^
<!-- gh-comment-id:2285691960 --> @khanhduytran0 commented on GitHub (Aug 13, 2024): Well, the issue boils down to the extraneous slash in tmp path ``` tmp//C0BB21DC ^ ```
Author
Owner

@boa-z commented on GitHub (Aug 13, 2024):

The problem mentioned in #82 still exist. Unfortunately, the fix version also crashed in this build. Following are part of the error log:

Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Error>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> : file write to (null) failed with posix error 2
Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Notice>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> summary for task failure {transaction_duration_ms=340, response_status=200, connection=1, reused=1, reused_after_ms=4175, request_start_ms=1, request_duration_ms=0, response_start_ms=306, response_duration_ms=0, request_bytes=71, response_bytes=232, cache_hit=false}
Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Error>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> finished with error [2] Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSErrorFailingURLStringKey=<private>, NSErrorFailingURLKey=<private>, _NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>}
<!-- gh-comment-id:2285802642 --> @boa-z commented on GitHub (Aug 13, 2024): The problem mentioned in #82 still exist. Unfortunately, the [fix version](https://github.com/hugeBlack/AidokuLC/releases/tag/v0.6.8) also crashed in this build. Following are part of the error log: ```text Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Error>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> : file write to (null) failed with posix error 2 Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Notice>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> summary for task failure {transaction_duration_ms=340, response_status=200, connection=1, reused=1, reused_after_ms=4175, request_start_ms=1, request_duration_ms=0, response_start_ms=306, response_duration_ms=0, request_bytes=71, response_bytes=232, cache_hit=false} Aug 13 17:15:23 JI LiveContainer(CFNetwork)[2689] <Error>: Task <F0414626-AC1D-4DFC-95D2-CF49D0528DF4>.<3> finished with error [2] Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSErrorFailingURLStringKey=<private>, NSErrorFailingURLKey=<private>, _NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>} ```
Author
Owner

@hugeBlack commented on GitHub (Aug 13, 2024):

Thank for your quick response!

I think this issue is resolved with new issues introduced. If I set the app's data folder to some that exist before LiveContainer updated (to 99b0c31), the app worked flawlessly. However, if I change it to some folder created before the update, it seems that LiveContainer can't find the Documents folder when trying to create a tmp folder and keeps trying to create new "Documents.sb-xxxxx" file inside the app's folder.

In this case, it kept creating folders like file:///var/mobile/Containers/Data/Application/B58FA70F-7448-48C1-99BA-4E4C8B33B2CA/Documents/Data/Application/D8CB47F3-653F-474B-9910-2FB954870CE7/Documents.sb-493f7faa-fgYcOs/, and this created folder is actually a 0kb file and apps cannot write to it.

However, if I switch the app's folder to C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491 that existed before update, it can correctly create and write to file:///private/var/mobile/Containers/Data/Application/B58FA70F-7448-48C1-99BA-4E4C8B33B2CA/tmp/C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491/tmp/NSIRD_Aidoku_UIiig8/

I tried to copy the content from the older folder to the new one, but this issue kept happening.

<!-- gh-comment-id:2286281178 --> @hugeBlack commented on GitHub (Aug 13, 2024): Thank for your quick response! I think this issue is resolved **with new issues introduced**. If I set the app's data folder to some that exist before LiveContainer updated (to 99b0c31), the app worked flawlessly. However, if I change it to some folder created before the update, it seems that LiveContainer can't find the Documents folder when trying to create a tmp folder and keeps trying to create new "Documents.sb-xxxxx" file inside the app's folder. In this case, it kept creating folders like `file:///var/mobile/Containers/Data/Application/B58FA70F-7448-48C1-99BA-4E4C8B33B2CA/Documents/Data/Application/D8CB47F3-653F-474B-9910-2FB954870CE7/Documents.sb-493f7faa-fgYcOs/`, and this created folder is actually a 0kb file and apps cannot write to it. However, if I switch the app's folder to `C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491` that existed before update, it can correctly create and write to `file:///private/var/mobile/Containers/Data/Application/B58FA70F-7448-48C1-99BA-4E4C8B33B2CA/tmp/C0BB21DC-4BB6-450A-B8C6-43CEE0CFA491/tmp/NSIRD_Aidoku_UIiig8/` I tried to copy the content from the older folder to the new one, but this issue kept happening.
Author
Owner

@khanhduytran0 commented on GitHub (Aug 13, 2024):

Does this (7f3868c) work?

<!-- gh-comment-id:2286293716 --> @khanhduytran0 commented on GitHub (Aug 13, 2024): Does [this](https://github.com/khanhduytran0/LiveContainer/actions/runs/10366538177) (7f3868c) work?
Author
Owner

@boa-z commented on GitHub (Aug 13, 2024):

Same problem.

<!-- gh-comment-id:2286316992 --> @boa-z commented on GitHub (Aug 13, 2024): Same problem.
Author
Owner

@hugeBlack commented on GitHub (Aug 13, 2024):

Does this (7f3868c) work?

This doesn't work either.

<!-- gh-comment-id:2286322457 --> @hugeBlack commented on GitHub (Aug 13, 2024): > Does [this](https://github.com/khanhduytran0/LiveContainer/actions/runs/10366538177) ([7f3868c](https://github.com/khanhduytran0/LiveContainer/commit/7f3868ce2991e00ae6c1da15d36f8c3125e65a3f)) work? This doesn't work either.
Author
Owner

@khanhduytran0 commented on GitHub (Aug 14, 2024):

In case you aren’t notified, I’ve made changes in debug branch, let me know if anything changes.

<!-- gh-comment-id:2288657775 --> @khanhduytran0 commented on GitHub (Aug 14, 2024): In case you aren’t notified, I’ve made changes in debug branch, let me know if anything changes.
Author
Owner

@hugeBlack commented on GitHub (Aug 14, 2024):

Thank you! 0b42688 do solve this issue! I think both issues can be closed now.

<!-- gh-comment-id:2288684702 --> @hugeBlack commented on GitHub (Aug 14, 2024): Thank you! 0b42688 do solve this issue! I think both issues can be closed now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/LiveContainer#106
No description provided.