python / python/cpython

ConfigParser chokes on conflict markers in stdin and throws AttributeError

Đang mở
#126,541 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

This is probably a duplicate of bug 107625, but I do not have a recent enough version of Python to check the behaviour.

Whether it is worth specially detecting conflict markers is something the code owners can decide.

To reproduce:

/tmp/py:

#!/usr/bin/python3

import configparser
import sys

sl = configparser.ConfigParser(allow_no_value=True)
sl.read_file(sys.stdin)

/tmp/z:

[list]
<<<<<<<< HEAD   (f12435 blah)
 foo
|||||||| BASE
 bar
========
 baz
>>>>>>>> CHANGE (faa768 blah)
$ </tmp/z /tmp/py
Traceback (most recent call last):
  File "/tmp/py", line 7, in <module>
    sl.read_file(sys.stdin)
  File "/usr/lib/python3.11/configparser.py", line 734, in read_file
    self._read(f, source)
  File "/usr/lib/python3.11/configparser.py", line 1077, in _read
    cursect[optname].append(value)
    ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

Notes:

  • sys.stdin seems to be needed to trigger this - deserves further investigation because it may point to a bad assumption or similar in the parser
  • allow_no_value is needed to trigger this

Finger of blame:

            if (cursect is not None and optname and
                cur_indent_level > indent_level):
                cursect[optname].append(value)

This does not check that cursect[optname] is present.

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong configparser.py tại ConfigParser._read, đặc biệt là phần xử lý tiếp dòng xung quanh dòng cursect[optname].append(value) được báo cáo. Tái hiện trường hợp với allow_no_value=True và đầu vào chứa conflict-marker thông qua stdin, sau đó thêm coverage hồi quy cho thấy parser không còn phát sinh AttributeError và xác minh rằng hành vi hiện có vẫn phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.