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 — Fix signed char handling in SSL record header version · Issue #161472 · python/cpython

Fix signed char handling in SSL record header version #161472

New issue
Copy link
New issue
Copy link
Open
#161474
Open
Fix signed char handling in SSL record header version#161472
#161474
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-SSLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@samitistfobos-dev
samitistfobos-dev
opened on Nov 6, 2026
Issue body actions

Bug report

Problem:

In _PySSL_msg_callback (SSL3_RT_HEADER branch, Modules/_ssl/debughelpers.c:55),
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.

version = cbuf[1] << 8 | cbuf[2];

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.

version = ((unsigned char)cbuf[1] << 8) | (unsigned char)cbuf[2];

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

  • gh-161472: Fix signed char handling in SSL record header version #161474

Activity

  1. samitistfobos-dev
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 6, 2026
  2. NekoAsakura
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-SSL
    on Nov 6, 2026
  3. samitistfobos-dev
    added 2 commits that reference this issue on Nov 6, 2026

    pythongh-161472: Add regression test for SSL record header versions

    6b1b06a

    pythongh-161472: Add regression test for SSL record header versions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-SSLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.