Skip to content

Commit

Permalink
[media-library] Fix getAssetsAsync crash when given invalid after
Browse files Browse the repository at this point in the history
… value on Android (#9466)

# Why

Fixes #9440 

Non-number string values caused `Integer.parseInt()` throwing uncaught `NumberFormatException` in background thread - this crashed the whole application.

# How

Surrounded `parseInt()` within a `try-catch` block with fallback to default value.

# Test Plan

Tested `getAssetsAsync({after: ... })` for different string values (both valid and invalid) on Android emulator.
  • Loading branch information
barthap committed Jul 29, 2020
1 parent 2f1b80c commit 9bca879
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/expo-media-library/CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@

### 🐛 Bug fixes

- Fixed `getAssetsAsync` crashes when given invalid `after` value on Android. ([#9466](https://github.com/expo/expo/pull/9466) by [@barthap](https://github.com/barthap))

## 8.4.0 — 2020-07-27

### 🐛 Bug fixes
Expand Down
Expand Up @@ -87,8 +87,12 @@ public GetQueryInfo invoke() {
}

// to maintain compatibility with IOS field after is in string object
mOffset = mInput.containsKey("after") ?
try {
mOffset = mInput.containsKey("after") ?
Integer.parseInt((String) mInput.get("after")) : 0;
} catch (NumberFormatException e) {
mOffset = 0;
}
return this;
}
}

0 comments on commit 9bca879

Please sign in to comment.