Skip to content

Commit

Permalink
Fixed: Do not pass -1 value to Cursor.get*() calls returned by `C…
Browse files Browse the repository at this point in the history
…ursor.getColumnIndex()` if column does not exist for when listing SAF documents
  • Loading branch information
agnostic-apollo committed Jan 12, 2025
1 parent 5467912 commit 724f275
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions app/src/main/java/com/termux/api/apis/SAFAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,35 @@ private static void statDocument(JsonWriter out, Context context, Uri uri) throw
if (c == null || c.getCount() == 0) {
return;
}
int index;
String mime = null;
c.moveToNext();
out.beginObject();
out.name("name");
out.value(c.getString(c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)));
out.name("type");
String mime = c.getString(c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE));
out.value(mime);

index = c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME);
if (index >= 0) {
out.name("name");
out.value(c.getString(index));
}

index = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE);
if (index >= 0) {
out.name("type");
mime = c.getString(index);
out.value(mime);
}

out.name("uri");

out.value(uri.toString());
if (! DocumentsContract.Document.MIME_TYPE_DIR.equals(mime)) {
out.name("length");
out.value(c.getInt(c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE)));
if (mime != null && !DocumentsContract.Document.MIME_TYPE_DIR.equals(mime)) {
index = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE);
if (index >= 0) {
out.name("length");
out.value(c.getInt(index));
}
}

out.endObject();
}
}
Expand Down

0 comments on commit 724f275

Please sign in to comment.