GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-161472: Fix signed char handling in SSL record header version by samitistfobos-dev · Pull Request #161474 · python/cpython

Conversation

@samitistfobos-dev

@samitistfobos-dev samitistfobos-dev commented Nov 6, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #161472

Problem:
In _PySSL_msg_callback (SSL3_RT_HEADER branch, Modules/_ssl/debughelpers.c), the TLS record header version bytes are read through a signed char pointer (const char *cbuf) and combined as version = cbuf[1] << 8 | cbuf[2]. OpenSSL invokes the message callback for a received record header before the version is validated, so both bytes are controlled by the remote peer. When cbuf[1] has its high bit set, a negative value is shifted left (undefined behaviour in C11); when cbuf[2] has its high bit set, sign extension clobbers the upper byte, and the Python msg_callback receives a wrong (negative or sign-extended) version value.
Solution: cast both header bytes to unsigned char before the shift and the OR, so the version is always assembled as an unsigned 16-bit value.

  • Issue: Fix signed char handling in SSL record header version #161472

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@samitistfobos-dev
samitistfobos-dev requested review from gpshead and picnixz as code owners November 6, 2026 10:58
@python-cla-bot

python-cla-bot Bot commented Nov 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Nov 6, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 6, 2026
Fix signed char handling in SSL record header version #161472
Open
@bedevere-app

bedevere-app Bot commented Nov 6, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samitistfobos-dev
Fix: INTEGER_OVERFLOW.CHECKED
41d571f
Problem:
In _PySSL_msg_callback (SSL3_RT_HEADER branch, Modules/_ssl/debughelpers.c),
the TLS record header version bytes are read through a signed char pointer
(const char *cbuf) and combined as version = cbuf[1] << 8 | cbuf[2]. OpenSSL
invokes the message callback for a received record header before the version
is validated, so both bytes are controlled by the remote peer. When cbuf[1]
has its high bit set, a negative value is shifted left (undefined behaviour
in C11); when cbuf[2] has its high bit set, sign extension clobbers the
upper byte, and the Python msg_callback receives a wrong (negative or
sign-extended) version value.
Solution: cast both header bytes to unsigned char before the shift and the
OR, so the version is always assembled as an unsigned 16-bit value.
Signed-off-by: Aleksandr Burlakov <[email protected]>
@samitistfobos-dev
samitistfobos-dev force-pushed the fix/pyssl_msg_callback_integer_overflow branch from 1049efc to 41d571f Compare November 6, 2026 12:47
@bedevere-app

bedevere-app Bot commented Nov 6, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samitistfobos-dev

samitistfobos-dev commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

This change has little impact for Python users, because it's limited to how TLS record header versions are reported through the SSL message callback. Normal TLS connections and record processing are unaffected, and the issue only manifests when handling malformed record headers containing bytes with the high bit set.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 6, 2026

Copy link
Copy Markdown
Member

No this still requires a NEWS entry.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 6, 2026

Copy link
Copy Markdown
Member

Please add a test if possible as well

samitistfobos-dev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@blurb-it
📜🤖 Added by blurb_it.
dc4dd8e
@samitistfobos-dev

samitistfobos-dev commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

I'll provide the test soon

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samitistfobos-dev

samitistfobos-dev commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Please add a test if possible as well

Provided

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samitistfobos-dev
pythongh-161472: Add regression test for SSL record header versions
f10388f
@samitistfobos-dev
samitistfobos-dev force-pushed the fix/pyssl_msg_callback_integer_overflow branch from 6b1b06a to f10388f Compare November 6, 2026 14:33
@samitistfobos-dev

samitistfobos-dev commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz Can you look again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead Awaiting requested review from gpshead gpshead is a code owner
@picnixz picnixz Awaiting requested review from picnixz picnixz is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Fix signed char handling in SSL record header version

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@samitistfobos-dev @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.