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 — `Packer.pack()` segfaults when its `default` callback calls `getbuffer()` · Issue #733 · msgpack/msgpack-python

Packer.pack() segfaults when its default callback calls getbuffer() #733

New issue
Copy link
New issue
Copy link
Open
Open
Packer.pack() segfaults when its default callback calls getbuffer()#733
Copy link

Description

@marinelay
marinelay
opened on Aug 28, 2026
Issue body actions

Summary

If the default callback obtains a memoryview through getbuffer() and then returns a sufficiently large value, Packer.pack() reallocates its internal buffer while the memoryview still references the old storage.
Accessing the memoryview afterward causes a segmentation fault, and an ASan build reports a heap-use-after-free.

Versions

msgpack 1.2.2, CPython 3.12.3, Ubuntu 24.04 x86_64, glibc 2.39.

Reproducer

import msgpack

packer = None
exported = None

class Unsupported:
    pass

def default(obj):
    global exported
    exported = packer.getbuffer()
    return b"A" * (2 * 1024 * 1024)

packer = msgpack.Packer(default=default, autoreset=False)
packer.pack([Unsupported()])
msgpack.unpackb(exported)

Running it produces:

Segmentation fault (core dumped)

Sanitizer result

An ASan build reports a heap-use-after-free in unpack_execute.
The allocation was freed by msgpack_pack_write after the callback exported a memoryview of the buffer.

ERROR: AddressSanitizer: heap-use-after-free
READ of size 1
    #0 unpack_execute msgpack/unpack_template.h:161
freed by:
    #1 msgpack_pack_write msgpack/pack.h:47

I found this while fuzzing Python C extension modules.
It looks like a bug to me, but I may be missing an intended constraint, so I would appreciate confirmation.

Activity

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

    No labels
    No labels

    Type

    No type

    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.