Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extension for stricter unicode validation #38

Merged
merged 3 commits into from
May 8, 2024

Conversation

bbannier
Copy link
Member

@bbannier bbannier commented May 8, 2024

This fixes our extension module for python/cpython#105375 which made unicode validation stricter (appeared e.g., in python-3.11.9).

bbannier added 2 commits May 8, 2024 07:38
This adds a top-level `pyproject.toml` and moves the minimally required
settings there from `setup.py`.
@bbannier bbannier self-assigned this May 8, 2024
@bbannier bbannier changed the title CI: Drop unsupported python-3.7, add python-3.12 Fix extension for stricter unicode validation May 8, 2024
@bbannier bbannier marked this pull request as ready for review May 8, 2024 07:27
@bbannier bbannier requested a review from timwoj May 8, 2024 07:27
@timwoj
Copy link
Member

timwoj commented May 8, 2024

We have some btests for pysubnettree in the repo. Could you add one for this?

@bbannier
Copy link
Member Author

bbannier commented May 8, 2024

We have some btests for pysubnettree in the repo. Could you add one for this?

This was actually flagged by one of the existing tests, see the failed CI run https://github.com/zeek/pysubnettree/actions/runs/8996870968/job/24714020545?pr=38. The issue there was that in binary test mode (which constructs addresses as bytes) the address value 1.3.3.255 used there encodes as b'\x01\x03\x03\xff' which is not valid unicode. When we try to construct an error message for the KeyError raised there this now fails (since we do not pin minor Python versions).

Do you still want me to add a dedicated test for this?


EDIT: I modified that test slightly so it now checks the exception message.

On lookup failure we would previously assume that binary addresses are
valid unicode when constructing exception messages. With
python/cpython#105375 which appeared e.g., in python-3.11.9 this starts
to cause failures as invalid unicode is now more consistently rejected; e.g., in
the test `pysubnettree.lookup` we construct a binary address `1.3.3.255`
which corresponds to `b'\x01\x03\x03\xff'` which is not valid unicode.

With this patch we set messages for `KeyError` from a `bytes` object
instead of a `str`, so that user's see e.g.,

    KeyError: b'1:3:3::3'

instead of the previous

    KeyError: '1:3:3::3'

This should still provide all the information necessary while working
with our interface which allows both `str` and `bytes` inputs.

The changes to `SubnetTree_wrap.cc` are generated automatically with
swig-3.0.12.
@timwoj timwoj force-pushed the topic/bbannier/fix-ci branch from 7fad27d to d61edb0 Compare May 8, 2024 19:04
@timwoj timwoj merged commit f00da03 into master May 8, 2024
10 checks passed
@timwoj timwoj deleted the topic/bbannier/fix-ci branch May 8, 2024 19:05
freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this pull request Jun 19, 2024
Also fix trace-summary python backtrace.

Intermittent crash:

    zeek/zeek@8c337bd

    threading/MsgThread: Decouple IO source and thread

    A MsgThread acting as an IO source itself can result in the
    scenario where the threading manager's heartbeat timer deletes
    a terminated MsgThread instance, but at the same time this
    instance is in the list of ready IO sources as determined by
    the IO loop in the current iteration.

trace-summary backtrace:

    zeek/pysubnettree#38

    Fix extension for stricter unicode validation

    This fixes our extension module for python/cpython#105375 which
    made unicode validation stricter.

Reported by:	Arne Welzel (crash), ogogon (backtrace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants