Fix Darwin file requests failing for assets with long titles - #1445
Open
yunusuztr wants to merge 1 commit into
Open
Fix Darwin file requests failing for assets with long titles#1445yunusuztr wants to merge 1 commit into
yunusuztr wants to merge 1 commit into
Conversation
Author
|
Follow-up on the verification status noted in the description: the patched build has now been tested on the device. Same iPhone, same two imported videos that previously failed, TestFlight build compiled from this patch:
The patch also compiled cleanly in CI against the current Xcode toolchain. One note in case it is useful for review: an earlier attempt to work around this from the Dart side by passing |
`makeAssetOutputPath` puts the asset title (or the resource's original
filename) straight into a path component. That string is not under the app's
control: assets imported from social apps carry the whole caption as their
title, hashtags and percent-escapes included.
Measured on a real device (iPhone, iOS 26, 2026-08-26): such videos produce a
path component past the 255-byte limit, and the `copyItemAtURL:toURL:` call in
`exportAssetToFile` fails with NSCocoaErrorDomain 514
(NSFileWriteInvalidFileNameError). Videos that play fine in Photos are reported
to the app as unavailable. Because every file-returning API routes through this
method, the same failure hits `loadFile`, `originFile` and `getMediaUrl`.
The title is decorative in this name: `localIdentifier` plus the modification
timestamp already identify the asset and its current version uniquely, so
shortening the title cannot introduce collisions.
This change:
* replaces `/` and `:` in the title portion, so a separator inside a title
cannot escape the cache directory;
* caps the title portion at 40 characters. Even if every character is a
4-byte code point that is 160 bytes, which leaves room for the ~65-byte
identifier/timestamp prefix and the extension inside the 255-byte limit.
`rangeOfComposedCharacterSequencesForRange:` keeps the cut off a combining
sequence so the result stays valid UTF-8.
Short titles are unaffected, so existing cache entries for ordinary camera
assets keep their names.
yunusuztr
force-pushed
the
fix/bound-export-cache-filename
branch
from
August 29, 2026 17:49
5a7b770 to
ee936eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS, every file-returning API fails with
NSCocoaErrorDomain 514(
NSFileWriteInvalidFileNameError) for assets whose title is long. In practice this meansvideos imported from social apps: they arrive in Photos with the whole caption as their
title, hashtags and percent-escapes included.
makeAssetOutputPathputs that title straight into a path component:With a caption-sized title the component goes past the 255-byte limit, so the
copyItemAtURL:toURL:inexportAssetToFilefails and the asset is reported to the app asunavailable. Because
loadFile,originFileandgetMediaUrlall route through this onemethod, they fail together.
From the user's side the symptom is misleading: a video that plays fine in Photos looks
broken in the app.
Evidence
Measured on a real device (iPhone, iOS 26). The app logged the raw platform error:
The quoted string is the start of the output filename, i.e. the
localIdentifierprefixthis method builds.
A discriminating test on the same device: videos recorded by the camera play (their titles
are like
IMG_1234.MOV), videos imported from Instagram do not.Passing an explicit
darwinFileTypedoes not help, since that only changes the extension andnot the basename. That was also verified on the device.
Fix
Bound and sanitise the title portion of the cache filename.
The title is decorative in this name:
localIdentifierand the modification timestampalready identify the asset and its current version, so shortening the title cannot introduce
collisions between assets or between versions of the same asset.
/and:are replaced, so a separator inside a title cannot escape the cache directory.is 160 bytes, which leaves room for the identifier, the timestamp and the extension inside
the 255-byte limit.
rangeOfComposedCharacterSequencesForRange:keeps the cut off acombining sequence, so the result stays valid UTF-8.
Short titles are untouched, so cache entries for ordinary camera assets keep their current
names and stay valid.
Reproduction
AssetEntity.loadFile(),originFileorgetMediaUrl()on it.NSCocoaErrorDomain 514; after it the file isreturned.
Verification status
The failure and its cause were verified on a real device, as described above. The author has
no Mac, so the patched build is verified only through CI compilation and on-device testing of
the resulting TestFlight build; I will follow up here with the device result. Flagging this
explicitly rather than implying a verification I did not do.