Skip to content

librustls: switch common.c's read_file to binary mode#650

Merged
cpu merged 1 commit into
rustls:mainfrom
cpu:ci/cpu-fix-ech-win-flake
Jun 26, 2026
Merged

librustls: switch common.c's read_file to binary mode#650
cpu merged 1 commit into
rustls:mainfrom
cpu:ci/cpu-fix-ech-win-flake

Conversation

@cpu

@cpu cpu commented Jun 26, 2026

Copy link
Copy Markdown
Member

Prior to ECH support all of the consumers of the common read_file() helper were loading text data (PEM encoded certs, keys, and CRLs). However, for ECH, we're loading a binary serialized ECH Config List structure.

On Windows specifically if we don't fopen() with mode==rb instead of mode==r we open the file in text mode, and certain byte sequences are translated:

In text mode, carriage return-line feed (CRLF) combinations are translated into single line feed (LF) characters on input,
...
When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function).

This in turn breaks ECH config deserialization when the config data happens to have those byte sequences. This manifests as a Windows-only flake of the ECH example unit test in CI, with the error:

client[8988]: failed to configure ECH with any provided config files

The fix is simple: we can use 'rb' as the mode in read_file() and avoid this issue.

Resolves #514

@cpu cpu self-assigned this Jun 26, 2026
@cpu

cpu commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

rustls-ffi / Clippy nightly (optional) (pull_request) Failing after 1m
rustls-ffi / Check for documentation errors (pull_request) Failing after 1m

Both need #649 to land first

@cpu

cpu commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

Not that it demonstrates too much except a lack of regressions, but here's a manually invoked daily tasks job passing on this branch.

Prior to ECH support all of the consumers of the common `read_file()`
helper were loading text data (PEM encoded certs, keys, and CRLs).
However, for ECH, we're loading a binary serialized ECH Config List
structure.

On Windows specifically if we don't `fopen()` with mode==rb
instead of mode==r we open the file in _text mode_, and certain byte
sequences are translated. This in turn breaks ECH config deserialization
when the config data happens to have those byte sequences. This
manifests as a Windows-only flake of the ECH example unit test in CI.

The fix is simple: we can use 'rb' as the mode in `read_file()` and
avoid this issue.
@cpu cpu force-pushed the ci/cpu-fix-ech-win-flake branch from 18e23ca to 258f320 Compare June 26, 2026 18:32
@cpu cpu enabled auto-merge (rebase) June 26, 2026 18:34
@cpu cpu merged commit 15cf801 into rustls:main Jun 26, 2026
46 checks passed
@cpu cpu deleted the ci/cpu-fix-ech-win-flake branch June 26, 2026 18:40
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.

Debug Windows ECH test flake

3 participants