Skip to content

net.vschannel: chunk large TLS payloads to fix 16KB EncryptMessage crash on Windows#26681

Merged
JalonSolov merged 5 commits into
vlang:masterfrom
whiter001:fix/vschannel-large-request-chunking-20260303
Mar 5, 2026
Merged

net.vschannel: chunk large TLS payloads to fix 16KB EncryptMessage crash on Windows#26681
JalonSolov merged 5 commits into
vlang:masterfrom
whiter001:fix/vschannel-large-request-chunking-20260303

Conversation

@whiter001

Copy link
Copy Markdown
Contributor

Problem

Windows SChannel enforces a maximum message size of 16,384 bytes per EncryptMessage call. Before this fix, sending an HTTPS request with a payload larger than 16 KB would:

  1. EncryptMessage failure – returns 0x80090329 when the input buffer exceeds cbMaximumMessage.
  2. Process crash – in the 32,768-byte case, a buffer offset overrun triggers invalid memory access, exiting with -1073741819 (0xC0000005 ACCESS_VIOLATION).

This affects any HTTPS POST/PUT with a large body (file uploads, JSON payloads, etc.) on Windows.

Fix

Query QueryContextAttributes(SECPKG_ATTR_STREAM_SIZES) for cbMaximumMessage and split the plaintext into chunks of that size (≤ 16,384 bytes) before calling EncryptMessage. Each chunk is encrypted and written to the socket independently.

Verification

A new probe tool cmd/tools/vschannel_16kb_httpbin_probe.v confirms the fix across the 16 KB boundary against https://httpbin.org/post:

Request size Before fix (c72ad76^) After fix
12,000 B ✅ OK ✅ OK
15,000 B ✅ OK ✅ OK
17,000 B EncryptMessage 0x80090329 + crash ✅ OK
24,000 B EncryptMessage 0x80090329 + crash ✅ OK
32,768 B RUNTIME ERROR: invalid memory access (exit -1073741819) ✅ OK

Reproduce / verify locally:

# verify fix (all should pass)
v run cmd/tools/vschannel_16kb_httpbin_probe.v --expect after

# reproduce bug: check out c72ad76^, rebuild, then:
v run cmd/tools/vschannel_16kb_httpbin_probe.v --expect before

Changes

  • vlib/net/vschannel/vschannel.c.v – chunk outbound TLS writes to ≤ cbMaximumMessage bytes
  • cmd/tools/vschannel_16kb_httpbin_probe.v – probe script for regression testing

baiyunfeng and others added 2 commits March 3, 2026 18:32
Split request payloads into cbMaximumMessage-sized chunks before EncryptMessage and send each encrypted record fully to avoid large-body crashes in Schannel path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a reproducible probe script that posts payloads around the 16KB boundary to https://httpbin.org/post and supports before/after expectation modes for regression verification.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 3, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows SChannel bug where sending HTTPS requests with payloads larger than 16 KB caused EncryptMessage to fail (or crash with an access violation), by chunking outbound TLS writes to at most cbMaximumMessage bytes per EncryptMessage call.

Changes:

  • vschannel.c: Wraps the encrypt-and-send logic in a loop that splits the plaintext into chunks no larger than cbMaximumMessage
  • vschannel_16kb_httpbin_probe.v: Adds a probe tool to verify correct behavior across the 16 KB boundary

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
thirdparty/vschannel/vschannel.c Core fix: loops over plaintext in cbMaximumMessage-sized chunks, encrypting and sending each independently
cmd/tools/vschannel_16kb_httpbin_probe.v Regression probe tool that spawns worker subprocesses and validates results against an expected pass/fail mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread thirdparty/vschannel/vschannel.c
Comment thread thirdparty/vschannel/vschannel.c
Comment thread cmd/tools/vschannel_16kb_httpbin_probe.v Outdated
Comment thread cmd/tools/vschannel_16kb_httpbin_probe.v Outdated
baiyunfeng added 2 commits March 3, 2026 19:37
- use os.new_process instead of os.execute to avoid shell escaping
  issues on Windows and separate stdout/stderr capture
- add explicit 'none' branch in expected_success_for_mode to make
  intent clear and guard against future unexpected mode values

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JalonSolov JalonSolov merged commit a1690ef into vlang:master Mar 5, 2026
74 checks passed
cestef pushed a commit to cestef/v that referenced this pull request Mar 9, 2026
…ash on Windows (vlang#26681)

* fix(vschannel): chunk large TLS request payloads on Windows

Split request payloads into cbMaximumMessage-sized chunks before EncryptMessage and send each encrypted record fully to avoid large-body crashes in Schannel path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test(tools): add vschannel 16kb httpbin probe script

Add a reproducible probe script that posts payloads around the 16KB boundary to https://httpbin.org/post and supports before/after expectation modes for regression verification.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* style(tools): vfmt vschannel_16kb_httpbin_probe.v

* refactor(tools): apply Copilot suggestions to vschannel probe

- use os.new_process instead of os.execute to avoid shell escaping
  issues on Windows and separate stdout/stderr capture
- add explicit 'none' branch in expected_success_for_mode to make
  intent clear and guard against future unexpected mode values

* fix(vschannel): cast send result before DWORD accumulation

---------

Co-authored-by: baiyunfeng <baiyunfeng@bailian.ai>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@whiter001 whiter001 deleted the fix/vschannel-large-request-chunking-20260303 branch March 11, 2026 01:30
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.

3 participants