Skip to content

fix: Prevent crash when mimeType is empty and fallback to file extension#658

Open
aymericmariaux wants to merge 14 commits into
mainfrom
fix-empty-mimetype
Open

fix: Prevent crash when mimeType is empty and fallback to file extension#658
aymericmariaux wants to merge 14 commits into
mainfrom
fix-empty-mimetype

Conversation

@aymericmariaux

Copy link
Copy Markdown
Contributor
  • Fix crash occurring when mimeType was empty or blank: indexOfLast('/') returned -1, which caused substring(-1) to throw StringIndexOutOfBoundsException
  • Ignore blank mimeType so FileType.guessFromFileName() and thumbnail generation can fallback to the file's extension when no valid mimeType is provided

Copilot AI review requested due to automatic review settings May 28, 2026 07:33

Copilot AI 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.

Pull request overview

This PR prevents crashes when mimeType is blank by avoiding unsafe MIME parsing and falling back to filename-based type detection where appropriate.

Changes:

  • Ignores blank MIME types in FileUi.fileType.
  • Safely derives thumbnail type information in previewUriForFile.
  • Falls back to the file name when MIME type is absent or malformed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt Uses filename-based file type detection when MIME type is blank.
app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferManagerExt.kt Avoids unsafe substring calls and skips thumbnail generation when URI or extension is unusable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/TransferUploaderV2.kt Outdated
Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/TransferUploader.kt Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MimeTypeExt.kt Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MimeTypeExt.kt Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@aymericmariaux aymericmariaux force-pushed the fix-empty-mimetype branch 2 times, most recently from bfc591d to 7a438d8 Compare May 29, 2026 12:24
@aymericmariaux aymericmariaux requested a review from Copilot May 29, 2026 12:25

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/UploadCommon.kt Outdated
Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/TransferUploaderV2.kt Outdated
Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/UploadUtils.kt Outdated
Comment thread app/src/main/java/com/infomaniak/swisstransfer/upload/UploadUtils.kt Outdated
Comment thread app/src/main/java/com/infomaniak/swisstransfer/ui/utils/MimeTypeExt.kt Outdated
- Fix crash occurring when `mimeType` was empty or blank: `indexOfLast('/')` returned `-1`, which caused `substring(-1)` to throw `StringIndexOutOfBoundsException`
- Ignore blank `mimeType` so `FileType.guessFromFileName()` and thumbnail generation can fallback to the file's extension when no valid mimeType is provided
Comment thread app/src/test/java/com/infomaniak/swisstransfer/ExtractExtensionUnitTest.kt Outdated
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

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