question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BufferedSource.readUtf8() causing DataFormatException: invalid distance too far back

See original GitHub issue

After I updated OkHttp to 4.8.0, I started receiving this error in the crash reporting tool.

Stack trace:

Non-fatal Exception: java.io.IOException: java.util.zip.DataFormatException: invalid distance too far back
       at okio.InflaterSource.readOrInflate(InflaterSource.java:99)
       at okio.InflaterSource.read(InflaterSource.java:49)
       at okio.GzipSource.read(GzipSource.java:69)
       at okio.internal.BufferKt.commonWriteAll(BufferKt.java:1061)
       at okio.Buffer.writeAll(Buffer.java:1655)
       at okio.internal.RealBufferedSourceKt.commonReadUtf8(RealBufferedSourceKt.java:171)
       at okio.RealBufferedSource.readUtf8(RealBufferedSource.java:309)
       ...
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

Example:

inline fun run(result: (Int, BufferedSource) -> Unit) {

    val json = JSONObject()
    json.put("foo", 123)
    val requestBody = json.toString().toRequestBody(JSON)

    val request = Request
        .Builder()
        .url("https://google.com")
        .post(requestBody)
        .build()

    val response = okHttp
        .newCall(request)
        .execute()

    response.body?.run {
        if (response.isSuccessful) {
            result(response.code, source())
        }
        close()
    }

}

And then:

run { _: Int, bufferedSource: BufferedSource ->
    val result = bufferedSource.readUtf8() //Crash here
}

Could be source() and then calling readUtf8() be the problem? The crash happened in a Galaxy Grand Prime Plus running Android 6.0.1.

Secondary log crash report (can be related):

Non-fatal Exception: java.io.IOException: ID1ID2: actual 0x00000800 != expected 0x00001f8b
       at okio.GzipSource.checkEqual(GzipSource.java:197)
       at okio.GzipSource.consumeHeader(GzipSource.java:110)
       at okio.GzipSource.read(GzipSource.java:62)
       at okio.internal.BufferKt.commonWriteAll(BufferKt.java:1061)
       at okio.Buffer.writeAll(Buffer.java:1655)
       at okio.internal.RealBufferedSourceKt.commonReadUtf8(RealBufferedSourceKt.java:171)
       at okio.RealBufferedSource.readUtf8(RealBufferedSource.java:309)
       ...
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at java.lang.Thread.run(Thread.java:818)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
swankjessecommented, Aug 3, 2020

A web search for the exception suggests the server is not returning well-formed gzip data. You should request the server’s administrators fix the problem.

In the interim you can disable compression with this request header:

Accept-Encoding: identity
Read more comments on GitHub >

github_iconTop Results From Across the Web

java.util.zip.ZipException: invalid distance too far back while ...
java.util.zip.ZipException: invalid distance too far back while decompressing ; 2. Then the compressed data has been corrupted. – Mark Adler.
Read more >
invalid distance too far back" exception for the attached file
PdfBox throws the following exception: Caused by: java.io.IOException: java.util.zip.DataFormatException: invalid distance too far back at ...
Read more >
[Samtools-help] invalid distance too far back error for picard ...
Re: [Samtools-help] invalid distance too far back error for picard ... I'm definitely not saying that I know the cause of the >...
Read more >
All Strings | PDF | Database Index - Scribd
() V ()[ (+%-4d) [%2d] %s (2)Error querying user properties (2)Read invalid user property value, ignoring it (2)Too many active user properties, ignoring...
Read more >
Corrupted Jar File Causes "java.util.zip.ZipException
Oracle WebLogic Server - Version 12.2.1.2.0 and later: Corrupted Jar File Causes "java.util.zip.ZipException: invalid distance too far back"
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found