Skip to content

Fix #351 - #357

Open
NSExceptional wants to merge 1 commit into
masterfrom
fix/351-crash-nonexistent-report-file
Open

Fix #351#357
NSExceptional wants to merge 1 commit into
masterfrom
fix/351-crash-nonexistent-report-file

Conversation

@NSExceptional

@NSExceptional NSExceptional commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Crash

Fatal Exception: NSInvalidArgumentException
Cannot read file at file:///.../....tsk-report

Root cause

-[TSKBackgroundReporter pinValidationFailedForHostname:...] writes the JSON pin-failure report to a temp file and then uploads it with -[NSURLSession uploadTaskWithRequest:fromFile:].

If writeToURL:options:error: fails (e.g. the device storage is full), the failure was only treated as fatal in DEBUG builds (see the #if DEBUG guard added for #32). In a production build, execution fell through and still called uploadTaskWithRequest:fromFile: with a file that was never written. CFNetwork validates the file synchronously at task-creation time and throws an uncaught NSInvalidArgumentException, crashing the app — exactly at TSKBackgroundReporter.m:218 in the reported stack trace.

FirebasePerformance appears in the trace only because it swizzles uploadTaskWithRequest:fromFile:; it is not the cause.

Fix

Return early when the report file cannot be written, so the reporter never hands a non-existent file to the upload task. DEBUG builds still raise (unchanged), preserving the behavior from #32.

@NSExceptional
NSExceptional requested a review from a team August 6, 2026 22:45
@NSExceptional
NSExceptional force-pushed the fix/351-crash-nonexistent-report-file branch from 4b1202a to 14c5bdc Compare August 7, 2026 00:28
@NSExceptional
NSExceptional changed the base branch from master to fix/build-unused-function August 7, 2026 00:28
@NSExceptional
NSExceptional force-pushed the fix/351-crash-nonexistent-report-file branch from 14c5bdc to d44a805 Compare August 7, 2026 00:31
@NSExceptional NSExceptional changed the title Fix crash when a pin-failure report file fails to write (#351) Fix #351 Aug 7, 2026

@alexanderdibenedetto alexanderdibenedetto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

uroboro
uroboro previously approved these changes Aug 7, 2026
Base automatically changed from fix/build-unused-function to master August 7, 2026 21:36
@NSExceptional
NSExceptional dismissed stale reviews from uroboro and alexanderdibenedetto August 7, 2026 21:36

The merge-base changed after approval.

TSKBackgroundReporter writes the JSON report to a temp file and then uploads it with -uploadTaskWithRequest:fromFile:. A write failure was only treated as fatal in DEBUG builds; in production the code fell through and still handed the non-existent file to the upload task. CFNetwork validates the file synchronously at task-creation time and throws an uncaught NSInvalidArgumentException ("Cannot read file at ..."), crashing the app.

Return early when the report file cannot be written so we never create an upload task for a file that does not exist.

Firebase appeared in the reported stack trace only because FirebasePerformance swizzles uploadTaskWithRequest:fromFile:; it was not the cause.
@NSExceptional
NSExceptional force-pushed the fix/351-crash-nonexistent-report-file branch from d44a805 to 4fe679f Compare August 7, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants