Umbrella issue: protobuf Python C Extension Analysis Report
I maintainer di solito rispondono entro 1 giorno
@runzw ci sta già lavorando.
Dal 22/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
What version of protobuf and what language are you using?
Version: 7.34.1 (pip package), also verified against current main branch source at python/ directory
Language: Python (upb C backend)
What supported operating system version are you using?
Linux (Ubuntu, x86_64)
What supported runtime / compiler version are you using?
Python 3.14.3+ (also affects 3.10-3.13)
What did you do?
We performed a systematic code review of the 10 C source files in python/ (the upb-based Python backend) using static analysis and manual review. We found multiple confirmed bugs, 7 of which we reproduced from pure Python scripts. Full report with analysis details: https://gist.github.com/devdanzin/b0eca1ded22efac92de4efe928916d46
The reproducible bugs are:
1. Segfault via strcmp(NULL) in numpy type detection (convert.c:213-222)
from google.protobuf import descriptor_pb2, descriptor_pool, message_factory
pool = descriptor_pool.DescriptorPool()
pool.Add(descriptor_pb2.FileDescriptorProto(
name="test.proto", syntax="proto3",
message_type=[descriptor_pb2.DescriptorProto(
name="TestMsg",
field=[descriptor_pb2.FieldDescriptorProto(
name="val", number=1, type=2, label=1)],
)],
))
TestMsg = message_factory.GetMessageClass(pool.FindMessageTypeByName("TestMsg"))
class NamelessMeta(type):
def __getattribute__(cls, name):
if name == "__name__":
raise AttributeError("no __name__")
return super().__getattribute__(name)
class Nameless(metaclass=NamelessMeta):
def __float__(self):
return 1.0
msg = TestMsg()
msg.val = Nameless() # Segmentation fault (core dumped)
2. MessageMeta_GetAttr swallows KeyboardInterrupt/MemoryError/SystemExit (message.c:2019)
# (same setup as above to get TestMsg)
class BombDescriptor:
def __get__(self, obj, objtype=None):
raise KeyboardInterrupt("should not be swallowed")
TestMsg.bomb = BombDescriptor()
try:
TestMsg.bomb
except AttributeError:
print("BUG: KeyboardInterrupt swallowed, replaced with AttributeError")
3. extension_ranges leaks memory on every access (descriptor.c:340-342)
import tracemalloc, gc
from google.protobuf import descriptor_pb2, descriptor_pool
pool = descriptor_pool.DescriptorPool()
pool.Add(descriptor_pb2.FileDescriptorProto(
name="test.proto", syntax="proto3",
message_type=[descriptor_pb2.DescriptorProto(
name="TestMsg",
field=[descriptor_pb2.FieldDescriptorProto(name="x", number=1, type=5, label=1)],
extension_range=[
descriptor_pb2.DescriptorProto.ExtensionRange(start=100, end=200),
descriptor_pb2.DescriptorProto.ExtensionRange(start=200, end=300),
],
)],
))
desc = pool.FindMessageTypeByName("TestMsg")
tracemalloc.start()
gc.collect()
before = tracemalloc.get_traced_memory()[0]
for _ in range(10000):
_ = desc.extension_ranges
gc.collect()
after = tracemalloc.get_traced_memory()[0]
print(f"Leaked {after - before} bytes over 10000 accesses")
# Leaked 321184 bytes over 10000 accesses
4. Descriptor container RichCompare swallows exceptions (descriptor_containers.c:249,527,752)
# (same setup to get desc)
fields = desc.fields_by_name
class BadEq:
def __eq__(self, other): raise RuntimeError("comparison error")
def __iter__(self): return iter([])
def __len__(self): return 0
print(fields == BadEq())
# Prints False -- RuntimeError silently swallowed
5. pop() clamps out-of-range index instead of raising IndexError (repeated.c:423-430)
# (same setup to get TestMsg with repeated int32 'values' field)
msg = TestMsg()
msg.values.extend([10, 20, 30])
print(msg.values.pop(999999))
# Prints 30 -- should raise IndexError
6-7. C/Python parity gaps: extended slice assignment works on C but raises ValueError on pure Python fallback; RepeatedComposite.__eq__ with lists returns True on C but raises TypeError on pure Python.
What did you expect to see
TypeErrororValueErrorinstead of segfaultKeyboardInterruptpropagated, not replaced withAttributeError- No memory growth from repeated
extension_rangesaccess RuntimeErrorpropagated from comparison, not silently swallowedIndexErrorfor out-of-rangepop()index
6-7. Consistent behavior between C and Python backends
What did you see instead?
Segmentation fault (core dumped)(exit code 139)AttributeErrorraised instead ofKeyboardInterrupt- ~32 bytes leaked per access (321KB over 10K calls with 2 extension ranges)
Falsereturned silently- Last element silently removed and returned
6-7. C backend accepts operations that Python backend rejects
Anything else we should know about your project / environment
The full analysis report covers approximately 30 unique bugs found across all 10 C files, including additional issues that require OOM to trigger (unchecked malloc/realloc, unchecked PyType_GenericAlloc at 15+ sites, double-free in descriptor container Items error paths) and a Py_DECREF on a stack-allocated C array (map.c:549) that is undefined behavior on every module import. The complete report with detailed analysis per bug is at the gist linked above.
The code review also identified 9 unguarded PyErr_Clear() calls, missing m_traverse/m_clear for module state with ~26 PyObject* members, and C/Python parity gaps in MergeFrom input handling and ExtensionDict.__eq__ semantics.
The code review was done with https://github.com/devdanzin/cext-review-toolkit.
- Lingua principale
- C++
- Stelle
- 72.2k
- Fork
- 16.4k
- Merge medio
- 1g 8h
- PR unite (30g)
- 342
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di protocolbuffers/protobuf
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
protocolbuffers/protobuf#31768 ·
I maintainer di solito rispondono entro 1 giorno
-
feature request packaging & distribution python
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31654 ·
I maintainer di solito rispondono entro 1 giorno
-
google-protobuf 0.36.2-release fails to compile for ARMv7: @progbits rejected in global_asm!Forse già presa @farisbasha l’ha presa 2 giorni fa. Apertabug help wanted rust
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31619 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Null pointer passed to memcpy in lupb_decode() when the second argument is nilForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug help wanted lua
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31392 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
upb: JSON encoder does not range-check Duration and Timestamp nanos (signed overflow on -2^31)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
protocolbuffers/protobuf#31032 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di protocolbuffers/protobuf
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 7 giorni
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/DirectXShaderCompiler#9155 ·
I maintainer di solito rispondono entro 2 giorni
-
Errors in 1.20 proseApertaCampaign DiD Campaign EI Campaign HttT Campaign TDG Campaign TSG Campaign WoF Enhancement Help Prose Stable 1.20
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wesnoth/wesnoth#11749 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno