capacitor
capacitor copied to clipboard
bug: Android Range Requests fail for large files
Bug Report
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 5.5.0 @capacitor/core: 5.5.0 @capacitor/android: 5.5.0 @capacitor/ios: 5.5.0
Installed Dependencies:
@capacitor/cli: 5.5.0 @capacitor/android: 5.5.0 @capacitor/core: 5.5.0 @capacitor/ios: 5.5.0
[info] Using Gemfile: RubyGems bundle installed [success] iOS looking great! 👌 [success] Android looking great! 👌
Platform(s)
- [x] Android
Current Behavior
Our app is working with video files and playing/fetching them mainly through range requests. Sometimes it also needs to access larger video files that have a size of 2 GB or more through range request to stream media within the WebView. When accessing a large media file (> 2.14 GB), the local file server fails due to an integer overflow when handling the local request. This is caused by the fact that the range headers are parsed into an Integer. The integer can only represent numbers up to 2147483647 Bytes (2,14... GB) so parsing the Integer from the range request fails.
Expected Behavior
The range request should also work for files larger than 2.14 GB.
Code Reproduction
Other Technical Details
The issue is caused within the handleLocalRequest function in android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java:202.
int totalRange = responseStream.available(); // totalRange integer overflow
String rangeString = request.getRequestHeaders().get("Range");
String[] parts = rangeString.split("=");
String[] streamParts = parts[1].split("-");
String fromRange = streamParts[0];
int range = totalRange - 1; // range integer overflow
if (streamParts.length > 1) {
range = Integer.parseInt(streamParts[1]);
}
Hey guys - did anyone find the time to look at this? I would appreciate it!