Skip to content

ISO-2022 seeking forgets state #70050

Open

Description

@vadmium
BPO 25863
Nosy @vstinner, @ezio-melotti, @vadmium, @serhiy-storchaka
Files
  • 25863-unittest.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2015-12-15.02:37:24.129>
    labels = ['extension-modules', 'type-bug', 'expert-unicode', 'expert-IO']
    title = 'ISO-2022 seeking forgets state'
    updated_at = <Date 2016-01-20.02:09:55.487>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2016-01-20.02:09:55.487>
    actor = 'martin.panter'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules', 'Unicode', 'IO']
    creation = <Date 2015-12-15.02:37:24.129>
    creator = 'martin.panter'
    dependencies = []
    files = ['41451']
    hgrepos = []
    issue_num = 25863
    keywords = ['patch']
    message_count = 4.0
    messages = ['256431', '257144', '257227', '258635']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'ezio.melotti', 'martin.panter', 'serhiy.storchaka', 'johnwalker']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue25863'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    Activity

    1. vadmium commented on Dec 15, 2015

      @vadmium
      MemberAuthor
      >>> from io import *
      >>> text = TextIOWrapper(BytesIO(), "iso-2022-jp")
      >>> text.write(u"P")
      1
      >>> text.tell()
      1
      >>> text.write(u"anter 正")
      7
      >>> text.tell()
      12
      >>> text.write(u"孝")
      1
      >>> text.seek(12)
      12
      >>> text.read()  # Should return 孝, not ASCII
      "9'"
      >>> text.buffer.getvalue()
      b"Panter \x1b$B@59'"
      >>> text.seek(1)
      1
      >>> text.read(7)
      'anter 正'
      >>> text.tell()  # Another bug?
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      UnicodeDecodeError: 'iso2022_jp' codec can't decode bytes in position 2-3: illegal multibyte sequence
    2. added
      type-bug
      on Dec 15, 2015
    3. ezio-melotti commented on Dec 28, 2015

      @ezio-melotti
      Member

      I confirmed the problem on default (3.6) and verified that it works as expected using utf-8 instead of iso-2022-jp.
      The code in the above message should be converted into a unittest, and related codecs should be checked as well.
      The problem is probably in Modules/cjkcodecs/_codecs_iso2022.c

    4. added
      extension-modules
      on Dec 28, 2015
    5. johnwalker commented on Dec 30, 2015

      johnwalkermannequin
      Mannequin

      Here is Martin's message as a unit test. It checks utf-8 and the iso-2022 family except iso-2022-cn and iso-2022-cn-ext because they are not supported. The errors occur with all iso-2022 charsets.

    6. vadmium commented on Jan 20, 2016

      @vadmium
      MemberAuthor

      After thinking about bpo-26158, I realize the seek() magic numbers don’t store any _encoder_ state, only _decoder_ state. That would explain the first bug (write, seek, then read). Though for this codec I suspect the decoder state is not recorded either, hence the bug with tell().

      Personally I don’t care much for seeking text files. But if someone wanted to fix the second bug, that might require fixing the incremental decoder’s getstate() implementation.

    7. transferred this issue fromon Apr 10, 2022
    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

      extension-modulestopic-IOtopic-unicodetype-bug

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions