From e16105d0593411dbb84e9b0cc5949fbb8d9e1737 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sun, 22 Jan 2023 23:11:50 +0100 Subject: [PATCH] Fix NRT and add more safety --- osu.Android/AndroidImportTask.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/osu.Android/AndroidImportTask.cs b/osu.Android/AndroidImportTask.cs index ec946f71f3..7273a6da5c 100644 --- a/osu.Android/AndroidImportTask.cs +++ b/osu.Android/AndroidImportTask.cs @@ -38,10 +38,11 @@ public override void DeleteFile() if (cursor == null) return null; - cursor.MoveToFirst(); + if (!cursor.MoveToFirst()) + return null; int filenameColumn = cursor.GetColumnIndex(IOpenableColumns.DisplayName); - string filename = cursor.GetString(filenameColumn); + string filename = cursor.GetString(filenameColumn) ?? uri.Path ?? string.Empty; // SharpCompress requires archive streams to be seekable, which the stream opened by // OpenInputStream() seems to not necessarily be. @@ -49,7 +50,12 @@ public override void DeleteFile() var copy = new MemoryStream(); using (var stream = contentResolver.OpenInputStream(uri)) + { + if (stream == null) + return null; + await stream.CopyToAsync(copy).ConfigureAwait(false); + } return new AndroidImportTask(copy, filename, contentResolver, uri); }