1 |
jlec 14/02/06 09:44:53 |
2 |
|
3 |
Added: numpy-1.8.0-f2py-insecure-temporary.patch |
4 |
Log: |
5 |
Backport fix for sec bug, #500484 |
6 |
|
7 |
(Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key B9D4F231BD1558AB!) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 dev-python/numpy/files/numpy-1.8.0-f2py-insecure-temporary.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/numpy/files/numpy-1.8.0-f2py-insecure-temporary.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/numpy/files/numpy-1.8.0-f2py-insecure-temporary.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: numpy-1.8.0-f2py-insecure-temporary.patch |
16 |
=================================================================== |
17 |
numpy/core/tests/test_memmap.py | 34 ++++++++++++++++------------------ |
18 |
numpy/core/tests/test_multiarray.py | 9 +++------ |
19 |
numpy/f2py/__init__.py | 22 +++++++++++----------- |
20 |
numpy/f2py/f2py2e.py | 4 ++-- |
21 |
numpy/lib/tests/test_io.py | 24 ++++++++++++++++-------- |
22 |
5 files changed, 48 insertions(+), 45 deletions(-) |
23 |
|
24 |
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py |
25 |
index 6de6319..10e7a08 100644 |
26 |
--- a/numpy/core/tests/test_memmap.py |
27 |
+++ b/numpy/core/tests/test_memmap.py |
28 |
@@ -1,7 +1,7 @@ |
29 |
from __future__ import division, absolute_import, print_function |
30 |
|
31 |
import sys |
32 |
-from tempfile import NamedTemporaryFile, TemporaryFile, mktemp |
33 |
+from tempfile import NamedTemporaryFile, TemporaryFile |
34 |
import os |
35 |
|
36 |
from numpy import memmap |
37 |
@@ -33,12 +33,11 @@ class TestMemmap(TestCase): |
38 |
assert_array_equal(self.data, newfp) |
39 |
|
40 |
def test_open_with_filename(self): |
41 |
- tmpname = mktemp('', 'mmap') |
42 |
- fp = memmap(tmpname, dtype=self.dtype, mode='w+', |
43 |
- shape=self.shape) |
44 |
- fp[:] = self.data[:] |
45 |
- del fp |
46 |
- os.unlink(tmpname) |
47 |
+ with NamedTemporaryFile() as tmp: |
48 |
+ fp = memmap(tmp.name, dtype=self.dtype, mode='w+', |
49 |
+ shape=self.shape) |
50 |
+ fp[:] = self.data[:] |
51 |
+ del fp |
52 |
|
53 |
def test_unnamed_file(self): |
54 |
with TemporaryFile() as f: |
55 |
@@ -55,17 +54,16 @@ class TestMemmap(TestCase): |
56 |
del fp |
57 |
|
58 |
def test_filename(self): |
59 |
- tmpname = mktemp('', 'mmap') |
60 |
- fp = memmap(tmpname, dtype=self.dtype, mode='w+', |
61 |
- shape=self.shape) |
62 |
- abspath = os.path.abspath(tmpname) |
63 |
- fp[:] = self.data[:] |
64 |
- self.assertEqual(abspath, fp.filename) |
65 |
- b = fp[:1] |
66 |
- self.assertEqual(abspath, b.filename) |
67 |
- del b |
68 |
- del fp |
69 |
- os.unlink(tmpname) |
70 |
+ with NamedTemporaryFile() as tmp: |
71 |
+ fp = memmap(tmp.name, dtype=self.dtype, mode='w+', |
72 |
+ shape=self.shape) |
73 |
+ abspath = os.path.abspath(tmp.name) |
74 |
+ fp[:] = self.data[:] |
75 |
+ self.assertEqual(abspath, fp.filename) |
76 |
+ b = fp[:1] |
77 |
+ self.assertEqual(abspath, b.filename) |
78 |
+ del b |
79 |
+ del fp |
80 |
|
81 |
def test_filename_fileobj(self): |
82 |
fp = memmap(self.tmpfp, dtype=self.dtype, mode="w+", |
83 |
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py |
84 |
index a0c4bcf..37b9931 100644 |
85 |
--- a/numpy/core/tests/test_multiarray.py |
86 |
+++ b/numpy/core/tests/test_multiarray.py |
87 |
@@ -2051,12 +2051,11 @@ class TestIO(object): |
88 |
self.x = rand(shape) + rand(shape).astype(np.complex)*1j |
89 |
self.x[0,:, 1] = [nan, inf, -inf, nan] |
90 |
self.dtype = self.x.dtype |
91 |
- self.filename = tempfile.mktemp() |
92 |
+ self.file = tempfile.NamedTemporaryFile() |
93 |
+ self.filename = self.file.name |
94 |
|
95 |
def tearDown(self): |
96 |
- if os.path.isfile(self.filename): |
97 |
- os.unlink(self.filename) |
98 |
- #tmp_file.close() |
99 |
+ self.file.close() |
100 |
|
101 |
def test_bool_fromstring(self): |
102 |
v = np.array([True, False, True, False], dtype=np.bool_) |
103 |
@@ -2084,7 +2083,6 @@ class TestIO(object): |
104 |
y = np.fromfile(f, dtype=self.dtype) |
105 |
f.close() |
106 |
assert_array_equal(y, self.x.flat) |
107 |
- os.unlink(self.filename) |
108 |
|
109 |
def test_roundtrip_filename(self): |
110 |
self.x.tofile(self.filename) |
111 |
@@ -2217,7 +2215,6 @@ class TestIO(object): |
112 |
s = f.read() |
113 |
f.close() |
114 |
assert_equal(s, '1.51,2.0,3.51,4.0') |
115 |
- os.unlink(self.filename) |
116 |
|
117 |
def test_tofile_format(self): |
118 |
x = np.array([1.51, 2, 3.51, 4], dtype=float) |
119 |
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py |
120 |
index ccdbd4e..fcfd185 100644 |
121 |
--- a/numpy/f2py/__init__.py |
122 |
+++ b/numpy/f2py/__init__.py |
123 |
@@ -28,20 +28,20 @@ def compile(source, |
124 |
from numpy.distutils.exec_command import exec_command |
125 |
import tempfile |
126 |
if source_fn is None: |
127 |
- fname = os.path.join(tempfile.mktemp()+'.f') |
128 |
+ f = tempfile.NamedTemporaryFile(suffix='.f') |
129 |
else: |
130 |
- fname = source_fn |
131 |
- |
132 |
- f = open(fname, 'w') |
133 |
- f.write(source) |
134 |
- f.close() |
135 |
- |
136 |
- args = ' -c -m %s %s %s'%(modulename, fname, extra_args) |
137 |
- c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' %(sys.executable, args) |
138 |
- s, o = exec_command(c) |
139 |
- if source_fn is None: |
140 |
- try: os.remove(fname) |
141 |
- except OSError: pass |
142 |
+ f = open(source_fn, 'w') |
143 |
+ |
144 |
+ try: |
145 |
+ f.write(source) |
146 |
+ f.flush() |
147 |
+ |
148 |
+ args = ' -c -m %s %s %s'%(modulename, f.name, extra_args) |
149 |
+ c = '%s -c "import numpy.f2py as f2py2e;f2py2e.main()" %s' % \ |
150 |
+ (sys.executable, args) |
151 |
+ s, o = exec_command(c) |
152 |
+ finally: |
153 |
+ f.close() |
154 |
return s |
155 |
|
156 |
from numpy.testing import Tester |
157 |
diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py |
158 |
old mode 100755 |
159 |
new mode 100644 |
160 |
index 011b430..b264ea3 |
161 |
--- a/numpy/f2py/f2py2e.py |
162 |
+++ b/numpy/f2py/f2py2e.py |
163 |
@@ -91,7 +91,7 @@ Options: |
164 |
--lower is assumed with -h key, and --no-lower without -h key. |
165 |
|
166 |
--build-dir <dirname> All f2py generated files are created in <dirname>. |
167 |
- Default is tempfile.mktemp(). |
168 |
+ Default is tempfile.mkdtemp(). |
169 |
|
170 |
--overwrite-signature Overwrite existing signature file. |
171 |
|
172 |
@@ -428,7 +428,7 @@ def run_compile(): |
173 |
del sys.argv[i] |
174 |
else: |
175 |
remove_build_dir = 1 |
176 |
- build_dir = os.path.join(tempfile.mktemp()) |
177 |
+ build_dir = tempfile.mkdtemp() |
178 |
|
179 |
_reg1 = re.compile(r'[-][-]link[-]') |
180 |
sysinfo_flags = [_m for _m in sys.argv[1:] if _reg1.match(_m)] |
181 |
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py |
182 |
index fdd78b2..caffada 100644 |
183 |
--- a/numpy/lib/tests/test_io.py |
184 |
+++ b/numpy/lib/tests/test_io.py |
185 |
@@ -4,7 +4,9 @@ import sys |
186 |
import gzip |
187 |
import os |
188 |
import threading |
189 |
-from tempfile import mkstemp, mktemp, NamedTemporaryFile |
190 |
+import shutil |
191 |
+import contextlib |
192 |
+from tempfile import mkstemp, mkdtemp, NamedTemporaryFile |
193 |
import time |
194 |
import warnings |
195 |
import gc |
196 |
@@ -21,6 +23,12 @@ from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal, |
197 |
assert_raises, run_module_suite) |
198 |
from numpy.testing import assert_warns, assert_, build_err_msg |
199 |
|
200 |
+@××××××××××.contextmanager |
201 |
+def tempdir(change_dir=False): |
202 |
+ tmpdir = mkdtemp() |
203 |
+ yield tmpdir |
204 |
+ shutil.rmtree(tmpdir) |
205 |
+ |
206 |
|
207 |
class TextIO(BytesIO): |
208 |
"""Helper IO class. |
209 |
@@ -145,14 +153,14 @@ class TestSavezLoad(RoundtripTest, TestCase): |
210 |
@np.testing.dec.slow |
211 |
def test_big_arrays(self): |
212 |
L = (1 << 31) + 100000 |
213 |
- tmp = mktemp(suffix='.npz') |
214 |
a = np.empty(L, dtype=np.uint8) |
215 |
- np.savez(tmp, a=a) |
216 |
- del a |
217 |
- npfile = np.load(tmp) |
218 |
- a = npfile['a'] |
219 |
- npfile.close() |
220 |
- os.remove(tmp) |
221 |
+ with tempdir() as tmpdir: |
222 |
+ tmp = open(os.path.join(tmpdir, "file.npz"), "w") |
223 |
+ np.savez(tmp, a=a) |
224 |
+ del a |
225 |
+ npfile = np.load(tmp) |
226 |
+ a = npfile['a'] |
227 |
+ npfile.close() |
228 |
|
229 |
def test_multiple_arrays(self): |
230 |
a = np.array([[1, 2], [3, 4]], float) |