Skip to content

fix(corekit): StringField's 'replace' decode fallback raises UnicodeError for codecs such as idna, on every Python #1706

Closed

Description

@JarryShaw

Describe the bug
StringField's decode fallback, pcapkit/corekit/fields/strings.py:209 (ret = value.decode(charset, 'replace')), sits outside any try. It assumes decoding with 'replace' cannot raise. A codec that rejects 'replace', or ignores the handler, therefore lets a UnicodeError escape unpack.

Reproduction
main at 8035434a2, CPython 3.14.8:

from pcapkit.corekit.fields.strings import StringField
StringField(length=1, encoding='idna', errors='ignore').unpack(b'a', {})
# UnicodeError: Unsupported error handling: replace   (field.py:587 -> strings.py:209)

This affects every Python version: idna supports only strict, so plain ASCII input raises whenever errors is not strict.

A scan of 20 encodings × 3 error modes × 264 inputs found:

Python escapes cause
3.8 1,056 all from :209: idna, plus punycode on non-ASCII input
3.14 660 idna only

punycode stopped escaping in 3.13: encodings/punycode.py no longer hard-codes a strict ASCII decode. The #1693 worker found this; I reproduced the idna case.

Expected behavior
unpack never raises a UnicodeError from pcapkit's own fallback. If even the fallback cannot decode, the field keeps the raw octets the way its other paths do, and a parse→rebuild round trip still gives the original bytes.

Activity

  1. added
    fixPull requests that fix a defect (fix: subject prefix)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 14, 2026
  2. moved this to Pending in PyPCAPKiton Oct 14, 2026
  3. JarryShaw commented on Oct 14, 2026

    @JarryShaw
    OwnerAuthor

    Blocked until #1707 merges. It edits the same function in pcapkit/corekit/fields/strings.py, where the fallback at :209 moves to :233.

  4. added
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 14, 2026
  5. moved this from Pending to Blocked in PyPCAPKiton Oct 14, 2026
  6. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    on Oct 14, 2026
  7. JarryShaw commented on Oct 14, 2026

    @JarryShaw
    OwnerAuthor

    #1707 has merged, so this is unblocked. A worker is on it.

  8. moved this from Blocked to WIP in PyPCAPKiton Oct 14, 2026
  9. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 14, 2026
  10. added this to the PyPCAPKit v1.5 milestone on Oct 26, 2026
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

    fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions