joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.83k stars 782 forks source link

java.lang.StringIndexOutOfBoundsException when using RNFetchBlob fetch for downloading file #313

Open ankit-makwana opened 5 years ago

ankit-makwana commented 5 years ago

RNFetchBlob version: 0.10.13 React Native version: 0.55.4 Android version: 8.1

Below is the crash log:


  at java.lang.String.substring (String.java:1975)
  at okhttp3.JavaNetCookieJar.decodeHeaderAsJavaNetCookies (JavaNetCookieJar.java:101)
  at okhttp3.JavaNetCookieJar.loadForRequest (JavaNetCookieJar.java:72)
  at com.facebook.react.modules.network.ReactCookieJarContainer.loadForRequest (ReactCookieJarContainer.java:40)
  at okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:84)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:125)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
  at com.RNFetchBlob.RNFetchBlobReq$3.intercept (RNFetchBlobReq.java:386)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
  at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
  at okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200)
  at okhttp3.RealCall$AsyncCall.execute (RealCall.java:147)
  at okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at java.lang.Thread.run (Thread.java:764)```
fernandocortes1990 commented 4 years ago

Any updates on this issue?

usenbekov commented 2 years ago

I think the reason is this: https://github.com/square/okhttp/issues/6897 It fails at this part:

if (value.startsWith("\"") && value.endsWith("\"")) {
  value = value.substring(1, value.length() - 1);
}

When the value contains only one double quote (") it fails, because the length of the value is one, but it tries to substring with the startIndex=1.

I added an issue to OkHttp, but I guess the quick solution would be, using an own fixed JavaNetCookieJar at https://github.com/joltup/rn-fetch-blob/blob/master/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java At this line (58): mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));

yschimke commented 2 years ago

I'm not sure when we will release a patch version of OkHttp, your own JavaNetCookieJar or a network interceptor that rewrites problem Cookie headers could be a good solution.