Repository navigation
fix(android): Read the SAF file size as a long - #25699
Merged
MartinZikmund merged 1 commit intoNov 5, 2026
Merged
MartinZikmund merged 1 commit into
MartinZikmund merged 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow change corrects size truncation and handles unknown sizes without introducing identified regressions.
No open issues 🎉
What changed in this PR
Fixes Android SAF file-size reporting for files of 2 GiB or more, addressing #25698 in Uno’s storage implementation.
Changes:
- Reads document sizes with
GetLonginto along, avoiding 32-bit truncation. - Explicitly returns zero for unknown sizes while preserving folder and fallback behavior.
| File | Description |
|---|---|
src/Uno.WinRT/Storage/Internal/SafHelpers.Android.cs |
Uses 64-bit size reads and checks for null provider values. |
Review effort: Balanced
Member
|
/azp run |
MartinZikmund
approved these changes
Oct 26, 2026
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Contributor
|
|
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.
GitHub Issue: closes #25698
PR Type:
🐞 Bugfix
What changed? 🚀
On Android,
GetBasicPropertiesAsyncfor Storage Access Framework files (the files the pickers return) read the provider's_sizecolumn withCursor.GetInt, into anint. A file of 2 GiB or more got a wrongSize: the high bits were lost, and a value that came out negative was sign-extended into a hugeulong.SafHelpers.GetBasicPropertiesAsyncnow reads_sizewithGetLong, asDocumentsContract.Document.COLUMN_SIZEis a long. It checksIsNullfirst: a provider that doesn't know the size reports null ("Size of a document, in bytes, or null if unknown"), andSizeis then 0.BasicProperties.Sizeis aulongwith no "unknown" value. 0 is also what AndroidXDocumentFile.length()returns "if the length is unknown", and Uno already uses that method when the provider returns no cursor. With the cursors I tried, a null_sizealready gave 0. Android documents the result ofgetIntandgetLongon a null value as implementation-defined, though, so the code no longer depends on it._sizethe provider reportsFolders (where the size isn't read) and providers that return no cursor (which use
DocumentFile.length(), already a long) are unchanged. No other Android storage code reads a size withGetInt.Tests: this PR has no automated test.
Uno.UI.RuntimeTestsbuilds once fornet10.0and runs on Android against the AndroidUno.WinRT, so a runtime test can't use Android types such as cursors or content URIs. The only public routes to a SAF file are the pickers, which need a user. A test would need a content provider declared in the SamplesApp manifest that reports large and null sizes, plus an Android-only test entry point intoUno.WinRT. I can add that if you want it.I verified the change on an Android 12 (API 31) emulator instead, with a throwaway app. It declares a content provider in a separate process, so the cursor crosses processes through a
CursorWindow, as it does from a real documents provider. The provider reports a_sizeof 1,234, 3 GiB, 5 GiB or null. The app callsSafHelpers.GetBasicPropertiesAsyncfromUno.WinRTbuilt before and after this change. The "Before" and "After" columns above are its output.PR Checklist ✅
Screenshots Compare Test Runresults.