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

Memory leak when parsing icon file #4329

Closed
guidovranken opened this issue Jan 2, 2020 · 1 comment · Fixed by #4381
Closed

Memory leak when parsing icon file #4329

guidovranken opened this issue Jan 2, 2020 · 1 comment · Fixed by #4381
Labels
Projects

Comments

@guidovranken
Copy link

The following produces a memory leak:

    poc = bytes([0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0xaf, 0x10, 0x00, 0x01, 0x00,
      0x04, 0x00, 0xe8, 0x02, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
      0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00,
      0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x12, 0x0b,
      0x00, 0x00, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x10, 0x00,
      0x00, 0x00, 0x00, 0x0b, 0x00, 0x00])
    p = ImageFile.Parser()
    try:
        p.feed(poc)
    except:
        pass

=================================================================
==10309==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 34 byte(s) in 1 object(s) allocated from:
    #0 0x54905d in malloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x580764 in _PyBytes_FromSize /src/cpython-3.8.1/Objects/bytesobject.c:86:31
    #2 0x580578 in PyBytes_FromStringAndSize /src/cpython-3.8.1/Objects/bytesobject.c:120:27
    #3 0x58eaa0 in bytes_subscript /src/cpython-3.8.1/Objects/bytesobject.c:1695:22
    #4 0x8f8a90 in PyObject_GetItem /src/cpython-3.8.1/Objects/abstract.c:154:26
    #5 0x7085be in _PyEval_EvalFrameDefault /src/cpython-3.8.1/Python/ceval.c:1607:29
    #6 0x59ce17 in function_code_fastcall /src/cpython-3.8.1/Objects/call.c:283:14
    #7 0x71b9ee in _PyObject_Vectorcall /src/cpython-3.8.1/./Include/cpython/abstract.h:127:11
    #8 0x7179ad in call_function /src/cpython-3.8.1/Python/ceval.c:5105:13
    #9 0x701f39 in _PyEval_EvalFrameDefault /src/cpython-3.8.1/Python/ceval.c:3597:23
    #10 0x719276 in _PyEval_EvalCodeWithName /src/cpython-3.8.1/Python/ceval.c:4416:14
    #11 0x59d279 in _PyFunction_Vectorcall /src/cpython-3.8.1/Objects/call.c:435:12
    #12 0x71b9ee in _PyObject_Vectorcall /src/cpython-3.8.1/./Include/cpython/abstract.h:127:11
    #13 0x7179ad in call_function /src/cpython-3.8.1/Python/ceval.c:5105:13
    #14 0x701f39 in _PyEval_EvalFrameDefault /src/cpython-3.8.1/Python/ceval.c:3597:23
    #15 0x59ce17 in function_code_fastcall /src/cpython-3.8.1/Objects/call.c:283:14
    #16 0x71b9ee in _PyObject_Vectorcall /src/cpython-3.8.1/./Include/cpython/abstract.h:127:11
    #17 0x7179ad in call_function /src/cpython-3.8.1/Python/ceval.c:5105:13
    #18 0x701f39 in _PyEval_EvalFrameDefault /src/cpython-3.8.1/Python/ceval.c:3597:23
    #19 0x59ce17 in function_code_fastcall /src/cpython-3.8.1/Objects/call.c:283:14
    #20 0x71b9ee in _PyObject_Vectorcall /src/cpython-3.8.1/./Include/cpython/abstract.h:127:11
    #21 0x7179ad in call_function /src/cpython-3.8.1/Python/ceval.c:5105:13
    #22 0x701f39 in _PyEval_EvalFrameDefault /src/cpython-3.8.1/Python/ceval.c:3597:23
    #23 0x719276 in _PyEval_EvalCodeWithName /src/cpython-3.8.1/Python/ceval.c:4416:14
    #24 0x59d279 in _PyFunction_Vectorcall /src/cpython-3.8.1/Objects/call.c:435:12
    #25 0x59ab40 in _PyObject_FastCallDict /src/cpython-3.8.1/Objects/call.c:96:15
    #26 0x59ec53 in _PyObject_Call_Prepend /src/cpython-3.8.1/Objects/call.c:887:14
    #27 0x64c7d9 in slot_tp_init /src/cpython-3.8.1/Objects/typeobject.c:6755:15
    #28 0x63d4a9 in type_call /src/cpython-3.8.1/Objects/typeobject.c:991:19
    #29 0x59afd1 in _PyObject_MakeTpCall /src/cpython-3.8.1/Objects/call.c:159:18

Initial analysis suggests this may be due to PyImaging_MapBuffer (reference increased but not decreased)?

@radarhere
Copy link
Member

I've created PR #4381. Do you agree that it resolves this?

Pillow automation moved this from New Issues to Closed Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants