me-no-dev / AsyncTCP

Async TCP Library for ESP32
GNU Lesser General Public License v3.0
714 stars 426 forks source link

Don't allow invalid window size when window scale is disabled #187

Open Skyslycer opened 3 weeks ago

Skyslycer commented 3 weeks ago

Recently I noticed the ESP crashing and tried to investigate the issue to the best of my abilities. This was happening multiple times per 10 minutes, and the ESP restarting every single time. I was shown this backtrace:

Backtrace: 0x400837b5:0x3ffcd960 0x4008d07d:0x3ffcd980 0x40092649:0x3ffcd9a0 0x400f9a4e:0x3ffcdad0 0x400f9afc:0x3ffcdaf0 0x400d572a:0x3ffcdb10 0x400f68c8:0x3ffcdb30

  #0  0x400837b5:0x3ffcd960 in panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408
  #1  0x4008d07d:0x3ffcd980 in esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:137
  #2  0x40092649:0x3ffcd9a0 in __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
  #3  0x400f9a4e:0x3ffcdad0 in tcp_update_rcv_ann_wnd at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp.c:951
      (inlined by) tcp_update_rcv_ann_wnd at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp.c:931
  #4  0x400f9afc:0x3ffcdaf0 in tcp_recved at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/core/tcp.c:991
  #5  0x400d572a:0x3ffcdb10 in _tcp_recved_api(tcpip_api_call_data*) at .pio/libdeps/esp32dev/AsyncTCP/src/AsyncTCP.cpp:419
  #6  0x400f68c8:0x3ffcdb30 in tcpip_thread_handle_msg at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:172
      (inlined by) tcpip_thread at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:154

I was able to track down the exact assert that was being triggered.

This was the assert being triggered and this was the configured option for LWIP_WND_SCALE.

Since I didn't know more about the error as I wasn't able to track down how exactly this was caused, I decided to add a check in the function AsyncTCP was handling. You can check the commit for the changes.

This is most likely just a temporary fix until somebody investigates this matter to identify the root issue, but for now it should do. Please point out any issues!