[Python-bugs-list] [ python-Bugs-462783 ] mmap bus error on linux

noreply@sourceforge.net noreply@sourceforge.net
Thu, 04 Apr 2002 09:22:55 -0800


Bugs item #462783, was opened at 2001-09-19 03:31
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=462783&group_id=5470

Category: Extension Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Andrew Dalke (dalke)
Assigned to: Nobody/Anonymous (nobody)
Summary: mmap bus error on linux

Initial Comment:
Not using the mmap module correctly can cause a
bus error under Linux.  This is a DEC, err, Compaq,
err, HP Alpha.

Here's a reproducible.  The problem appears to
be trying to mmap past the end of the file,
since putting in a "seek(0)" at the indicated
spot fixes things.


[dalke@pw600a src]$ ./python
Python 2.2a3+ (#6, Sep 17 2001, 05:05:24)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] 
on linux2
Type "help", "copyright", "credits" or "license" for 
more information.
>>> file = open("test.dat", "w+")
>>> file.write("12345")
>>> import mmap
>>> # Forgot to do "file.seek(0)" here
>>> s = mmap.mmap(file.fileno(), 5)
>>> s[:5]
Bus error
[dalke@pw600a src]$ gdb ./python core
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General 
Public License, and you are
welcome to change it and/or distribute copies of it 
under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show 
warranty" for details.
This GDB was configured as "alpha-redhat-linux"...

warning: "/home/dalke/cvses/python/dist/src/core": 
ambiguous core format, 2 handle
rs match

warning: core file may not match specified executable 
file.
Core was generated by `perl'.
Program terminated with signal 8, Floating point 
exception.
#0  0x12004d7b8 in com_assert_stmt (c=0x0, n=0x0) at 
Python/compile.c:717
717             PyString_AsString(c->c_code)[c-
>c_nexti++] = byte;
(gdb) where
#0  0x12004d7b8 in com_assert_stmt (c=0x0, n=0x0) at 
Python/compile.c:717
(gdb)

                     Andrew
                     dalke@dalkescientific.com


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-04 12:22

Message:
Logged In: YES 
user_id=6380

Note that Greg Green has uploaded a fix for this, patch
536578.

Andrew, can you test that patch?

----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2001-10-22 19:37

Message:
Logged In: YES 
user_id=31392

I can reproduce the problem just fine on Intel Linux, but
I'm not really sure what we can do about it.  When I run the
test, I get a bus error when it tries to dereference
self->data in mmap_slice().  I don't see how we can prevent
the bus error short of checking the length of the file
before we map it.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=462783&group_id=5470