Bug 674369 - lambda in ctypes causes MemoryError exception in PIL
Summary: lambda in ctypes causes MemoryError exception in PIL
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora EPEL
Classification: Fedora
Component: python26
Version: el5
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Adrien Devresse
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-02-01 16:05 UTC by jspam
Modified: 2018-11-08 01:15 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2017-04-06 10:03:24 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description jspam 2011-02-01 16:05:50 UTC
Description of problem:
in /usr/lib64/python2.6/ctypes/__init__.py:546

# XXX for whatever reasons, creating the first instance of a callback
# function is needed for the unittests on Win64 to succeed.  This MAY
# be a compiler bug, since the problem occurs only when _ctypes is
# compiled with the MS SDK compiler.  Or an uninitialized variable?
CFUNCTYPE(c_int)(lambda: None)


causes a memory error in certain, unreproducible, conditions when trying to import Image from PIL


Version-Release number of selected component (if applicable):
python26-2.6.5-5.el5

How reproducible:
not very

Steps to Reproduce:
1. ????
2. from PIL import Image
3. MemoryError
  
Actual results:
MemoryError exception

Expected results:
PIL.Image imports successfully

Additional info:

deleting line 546 does cause the error not to happen

Comment 1 Dave Malcolm 2011-02-02 00:29:40 UTC
MemoryError indicates an out-of-memory condition.  Is the system low on memory?

Which architecture is this on? x86_64?

Are you installing PIL via an rpm package?  If so, what name-version-release?

Comment 2 jspam 2011-02-02 01:42:01 UTC
Yes, it is x86_64. I rebuilt the RHEL5 python-imaging using python26. The version is 1.1.5.


I should add that just importing PIL is not enough to reproduce. My suggestion is just to delete the line in ctypes:


CFUNCTYPE(c_int)(lambda: None)


seeing as it's to pass the windows unit tests or so says the comment it should be a minimal change.

Thanks

Comment 3 Ravindra Tripathi 2012-02-14 08:33:16 UTC
I have also faced the similar issue after updating the python2.6 using yum.

PIL version: 1.1.7
Kernel version: 2.6.18-238.19.1.el5 
64 bit OS
SELinux is disabled on our system.
mod_python, mod_wsgi, python26 and apache are all installed from yum repositories

We have a django application and deployed on apache using mod_python.( got the same issue with mod_wsgi also)

I also tried app with python2.7 compiled version, and got the same exception.

commenting out the line CFUNCTYPE(c_int)(lambda: None) in both the cases(python repository version and compiled version) fixed the issue for us.


I have few queries
Is it safe to comment this line out, will there be any impact? Since it was working earlier is there anything in the update that broke this?

Comment 4 jspam 2012-02-14 19:09:43 UTC
I am pretty sure we resolved this by making sure $HOME pointed to a writeable location.

We mount /tmp noexec and libffi wants to mmap and then exec something in a tmpdir. libffi prefers $HOME if it's writeable.

You might have a similar problem

Comment 5 Fedora End Of Life 2017-04-06 10:03:24 UTC
Fedora EPEL 5 changed to end-of-life (EOL) status on 2017-03-31. Fedora EPEL 5
is no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora
or Fedora EPEL, please feel free to reopen this bug against that version. If
you are unable to reopen this bug, please file a new report against the current
release. If you experience problems, please add a comment to this bug.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 6 Utsav Popli 2018-11-08 01:15:15 UTC
Hi,
This particular exception was thrown when I was running mod_wsgi with apache with selinux enabled. 


System: 
Centos 6.10 
2.6.32-754.6.3.el6.x86_64


Scenario: 
I was trying to python script from apache (using mod_wsgi). I ran into this issue:
CFUNCTYPE(c_int)(lambda: None)


First observation was apache was unable to write to a file "Permission denied error" 

So I create a file manually and setup the file permissions chmod +x and chown -R apache:apache to the file 

Still issue persisted. 
I disabled SeLinux and rebooted machine. Everything worked fine afterwards !!!!


This is what I did to fix this: 

Step 1: 

              semodule -i myhttp.pp


Step2: 
        semanage fcontext -a -t httpd_sys_script_exec_t "<file directory path that will be created by python script>(/.*)?"
        semanage fcontext -a -t httpd_sys_script_exec_t "path to python script?"


        restorecon -Rv <file directory path that will be created by python>
        restorecon -Rv <path to python script>


Note You need to log in before you can comment on or make changes to this bug.