Skip to content

🐛 [Bug]: Segfault with WS compression #1136

Open
@nuttert

Description

Bug Description

I got the segfault, when I turned on a compression:

	c.EnableWriteCompression(true)
	c.SetCompressionLevel(flate.BestSpeed + 1)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x6f56a3]
goroutine 291238 [running]:
github.com/valyala/fasthttp.(*hijackConn).SetWriteDeadline(0x0?, {0x0?, 0x0?, 0x0?})
        <autogenerated>:1 +0x23
github.com/fasthttp/websocket.(*Conn).write(0xc008e04420, 0x0, {0x0?, 0x0?, 0x0?}, {0xc010b07b0a, 0x404, 0x404}, {0x0, 0x0, ...})
        /go/pkg/mod/github.com/fasthttp/[email protected]/conn.go:425 +0x176
github.com/fasthttp/websocket.(*messageWriter).flushFrame(0xc00e7144e0, 0x0, {0x0?, 0x0?, 0x0?})
        /go/pkg/mod/github.com/fasthttp/[email protected]/conn.go:676 +0x3c6
github.com/fasthttp/websocket.(*messageWriter).ncopy(0xc00e7144e0, 0xee)
        /go/pkg/mod/github.com/fasthttp/[email protected]/conn.go:701 +0x36
github.com/fasthttp/websocket.(*messageWriter).Write(0xc00e7144e0, {0xc0000f6068?, 0xf2, 0x694538?})
        /go/pkg/mod/github.com/fasthttp/[email protected]/conn.go:728 +0xc8
github.com/fasthttp/websocket.(*truncWriter).Write(0xc013272400, {0xc0000f6068?, 0x3e000000000000?, 0x6?})
        /go/pkg/mod/github.com/fasthttp/[email protected]/compression.go:92 +0x216
github.com/klauspost/compress/flate.(*huffmanBitWriter).writeTokens(0xc0000f6008, {0xc00576a314, 0xc005d93cef?, 0x310?}, {0xc00031a000, 0x2?, 0x17ceb0e7144e0?}, {0xc00ce24080, 0x1e, 0x20})
        /go/pkg/mod/github.com/klauspost/[email protected]/flate/huffman_bit_writer.go:966 +0x68d
github.com/klauspost/compress/flate.(*huffmanBitWriter).writeBlockDynamic(0xc0000f6008, 0xc00576a088, 0x0, {0xc003e00000, 0xffff, 0xffff}, 0x1?)
        /go/pkg/mod/github.com/klauspost/[email protected]/flate/huffman_bit_writer.go:767 +0x894
github.com/klauspost/compress/flate.(*compressor).storeFast(0xc00576a000)
        /go/pkg/mod/github.com/klauspost/[email protected]/flate/deflate.go:767 +0x278
github.com/klauspost/compress/flate.(*compressor).write(0xc00576a000, {0xc015f4e000?, 0x249aa9, 0xc00e7144e0?})
        /go/pkg/mod/github.com/klauspost/[email protected]/flate/deflate.go:783 +0x88
github.com/klauspost/compress/flate.(*Writer).Write(...)
        /go/pkg/mod/github.com/klauspost/[email protected]/flate/deflate.go:971
github.com/fasthttp/websocket.(*flateWriteWrapper).Write(0xc008e04420?, {0xc015f4e000?, 0x7f7758288f18?, 0x10?})
        /go/pkg/mod/github.com/fasthttp/[email protected]/compression.go:106 +0x25
github.com/fasthttp/websocket.(*Conn).WriteMessage(0xc00a104220?, 0x8c59d5?, {0xc015f4e000, 0x249aa9, 0x2a0000})
        /go/pkg/mod/github.com/fasthttp/[email protected]/conn.go:837 +0x186
microservices/routers/ws/impl.(*Router).writeMessage(0x8124a0?, 0xc001d50200, {0xc015f4e000, 0x249aa9, 0x2a0000}, {0xc00a104220, 0xf})

How to Reproduce

Steps to reproduce the behavior:
Turn on the compression and after several hours(if you actively use the server) you will get a segfault

Expected Behavior

I expect that compression should work fine without segfaults

Contrib package Version

contrib/websocket v1.3.0

Code Snippet (optional)

c.EnableWriteCompression(true)
c.SetCompressionLevel(flate.BestSpeed + 1)

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Assignees

No one assigned

    Labels

    ☢️ BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions