automation.VARIANT._set_value assumes c_char.value has length 1
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
Direzione di ricerca
Inizia in comtypes/automation.py, in VARIANT._set_value, e riproduci il ramo c_char con l’esempio sintetico WeirdChar dell’issue. Esamina i test VARIANT nelle vicinanze, se presenti, e considera completato il lavoro quando l’errore generico di ord() sarà sostituito dal comportamento validato e contestuale previsto per gli input c_char.value multi-byte.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment data
- OS: Windows Server 2022 / Windows 10
- Python version: 3.13.12
- comtypes version: 1.4.16
- COM type libraries involved in the real-world trigger: UI Automation (
IUIAutomation)
Code snippet
This synthetic reproducer exercises the exact failing branch in comtypes/automation.py:
from ctypes import c_char
from comtypes.automation import VARIANT
class WeirdChar(c_char):
@property
def value(self):
return b"hello"
VARIANT(WeirdChar(b"h"))
Traceback on comtypes 1.4.16:
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "...\site-packages\comtypes\automation.py", line 199, in __init__
self.value = args[0]
File "...\site-packages\comtypes\automation.py", line 347, in _set_value
self._.VT_UI1 = ord(value.value)
TypeError: ord() expected a character, but string of length 5 found
The current branch is:
elif isinstance(value, c_char):
self._.VT_UI1 = ord(value.value)
self.vt = VT_UI1
Situation reproducing steps
- Import
VARIANTfromcomtypes.automation - Pass a
c_charinstance whose.valueis longer than one byte toVARIANT(...) automation.pycallsord(value.value)ord()raisesTypeErrorbecause the input length is greater than 1
In a real application, I hit this through COM/UI Automation property marshaling. During tree traversal, a COM property eventually reached VARIANT._set_value as a c_char whose .value was unexpectedly multi-byte, which caused the same traceback above.
Expected behavior
comtypes should not assume that c_char.value is always length 1 before calling ord().
At minimum, this branch should validate the length explicitly and raise a more direct error with context. If treating the underlying data as a byte is the intended behavior, raw[0] after validation would also avoid the current ord() failure path.
Actual behavior
comtypes raises a generic TypeError from ord():
TypeError: ord() expected a character, but string of length 5 found
When this happens in COM-driven code, the error bubbles out of a deep marshaling path and is difficult for downstream callers to diagnose or handle precisely.
Additional context
I do not yet have a minimal pure-COM reproducer outside the larger application, so the code snippet above is synthetic. I am filing this because it demonstrates the exact failing branch and matches the traceback seen in the real COM/UI Automation scenario.
- Lingua principale
- Python
- Stelle
- 346
- Fork
- 107
- Merge medio
- 22h 5m
- PR unite (30g)
- 15
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 enthought/comtypes
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
typing
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
[CI] Run tests on ARMApertaci tests
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
enthought/comtypes#925 · 11 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Proposal: Fix `NTDebugHandler` and Deprecate `setup_logging` in `logutil.py`.Forse già presa @junkmd l’ha presa 22 giorni fa. Apertabug tests
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
enthought/comtypes#873 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di enthought/comtypes
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
topoteretes/cognee#5773 ·
I maintainer di solito rispondono entro 1 giorno
-
MiKTeX: a failed build reports no errors because texify --quiet switches the log to file:line: styleAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
SublimeText/LaTeXTools#1718 ·