Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix Android Camera Roll crash on mime type guessing #24780

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import java.net.URLConnection;
import java.net.URL;

// TODO #6015104: rename to something less iOSish
Expand Down Expand Up @@ -388,7 +387,8 @@ private static void putEdges(
WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess =
putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex);
putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, dataIndex,
mimeTypeIndex);
if (imageInfoSuccess) {
putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(media, node, longitudeIndex, latitudeIndex);
Expand Down Expand Up @@ -423,20 +423,15 @@ private static boolean putImageInfo(
int idIndex,
int widthIndex,
int heightIndex,
int dataIndex) {
int dataIndex,
int mimeTypeIndex) {
WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.parse("file://" + media.getString(dataIndex));
image.putString("uri", photoUri.toString());
float width = media.getInt(widthIndex);
float height = media.getInt(heightIndex);

String mimeType;
try {
mimeType = URLConnection.guessContentTypeFromName(photoUri.toString());
} catch (StringIndexOutOfBoundsException e) {
FLog.e(ReactConstants.TAG, "Unable to guess content type from " + photoUri.toString(), e);
throw e;
}
String mimeType = media.getString(mimeTypeIndex);

if (mimeType != null
&& mimeType.startsWith("video")) {
Expand Down