Skip to content

fix(Net): Handle negative available() return in receiveBytes (#4537)#5127

Merged
matejk merged 1 commit intomainfrom
fix/4537-available-negative-return
Dec 18, 2025
Merged

fix(Net): Handle negative available() return in receiveBytes (#4537)#5127
matejk merged 1 commit intomainfrom
fix/4537-available-negative-return

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Dec 18, 2025

Summary

Fixes #4537 - On Windows, sending UDP to a closed port causes available() to return -1 due to ICMP "connection reset" error. When this negative value was used for buffer allocation in receiveBytes(Buffer&), it caused std::bad_array_new_length crash.

Changes:

  • SocketImpl::receiveBytes(Buffer&): Check for negative available() and throw IOException
  • SocketProactor: Check available() > 0 before processing, with explicit cast to avoid signed/unsigned comparison
  • Added test case testClosedPortError to verify the fix

Supersedes #4539 (implements the maintainer's preferred approach of fixing callers rather than having available() throw).

Co-Authored-By: Andrew Auclair <mightymalakai33@gmail.com>
@matejk matejk force-pushed the fix/4537-available-negative-return branch from a030e13 to 7801fc6 Compare December 18, 2025 00:08
@matejk matejk merged commit 8057019 into main Dec 18, 2025
85 of 86 checks passed
@matejk matejk deleted the fix/4537-available-negative-return branch December 18, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Net: Socket::available causes connection reset on Windows UDP sockets

1 participant