Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
84d28b4e
Commit
84d28b4e
authored
Dec 14, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19623: Fixed writing to unseekable files in the aifc module.
parent
5da107ac
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
62 deletions
+103
-62
Lib/aifc.py
Lib/aifc.py
+8
-3
Lib/test/audiotests.py
Lib/test/audiotests.py
+62
-0
Lib/test/test_aifc.py
Lib/test/test_aifc.py
+12
-29
Lib/test/test_sunau.py
Lib/test/test_sunau.py
+8
-15
Lib/test/test_wave.py
Lib/test/test_wave.py
+11
-15
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/aifc.py
View file @
84d28b4e
...
@@ -771,7 +771,10 @@ class Aifc_write:
...
@@ -771,7 +771,10 @@ class Aifc_write:
self
.
_datalength
=
(
self
.
_datalength
+
3
)
//
4
self
.
_datalength
=
(
self
.
_datalength
+
3
)
//
4
if
self
.
_datalength
&
1
:
if
self
.
_datalength
&
1
:
self
.
_datalength
=
self
.
_datalength
+
1
self
.
_datalength
=
self
.
_datalength
+
1
try
:
self
.
_form_length_pos
=
self
.
_file
.
tell
()
self
.
_form_length_pos
=
self
.
_file
.
tell
()
except
(
AttributeError
,
OSError
):
self
.
_form_length_pos
=
None
commlength
=
self
.
_write_form_length
(
self
.
_datalength
)
commlength
=
self
.
_write_form_length
(
self
.
_datalength
)
if
self
.
_aifc
:
if
self
.
_aifc
:
self
.
_file
.
write
(
b'AIFC'
)
self
.
_file
.
write
(
b'AIFC'
)
...
@@ -783,6 +786,7 @@ class Aifc_write:
...
@@ -783,6 +786,7 @@ class Aifc_write:
self
.
_file
.
write
(
b'COMM'
)
self
.
_file
.
write
(
b'COMM'
)
_write_ulong
(
self
.
_file
,
commlength
)
_write_ulong
(
self
.
_file
,
commlength
)
_write_short
(
self
.
_file
,
self
.
_nchannels
)
_write_short
(
self
.
_file
,
self
.
_nchannels
)
if
self
.
_form_length_pos
is
not
None
:
self
.
_nframes_pos
=
self
.
_file
.
tell
()
self
.
_nframes_pos
=
self
.
_file
.
tell
()
_write_ulong
(
self
.
_file
,
self
.
_nframes
)
_write_ulong
(
self
.
_file
,
self
.
_nframes
)
if
self
.
_comptype
in
(
b'ULAW'
,
b'ulaw'
,
b'ALAW'
,
b'alaw'
,
b'G722'
):
if
self
.
_comptype
in
(
b'ULAW'
,
b'ulaw'
,
b'ALAW'
,
b'alaw'
,
b'G722'
):
...
@@ -794,6 +798,7 @@ class Aifc_write:
...
@@ -794,6 +798,7 @@ class Aifc_write:
self
.
_file
.
write
(
self
.
_comptype
)
self
.
_file
.
write
(
self
.
_comptype
)
_write_string
(
self
.
_file
,
self
.
_compname
)
_write_string
(
self
.
_file
,
self
.
_compname
)
self
.
_file
.
write
(
b'SSND'
)
self
.
_file
.
write
(
b'SSND'
)
if
self
.
_form_length_pos
is
not
None
:
self
.
_ssnd_length_pos
=
self
.
_file
.
tell
()
self
.
_ssnd_length_pos
=
self
.
_file
.
tell
()
_write_ulong
(
self
.
_file
,
self
.
_datalength
+
8
)
_write_ulong
(
self
.
_file
,
self
.
_datalength
+
8
)
_write_ulong
(
self
.
_file
,
0
)
_write_ulong
(
self
.
_file
,
0
)
...
...
Lib/test/audiotests.py
View file @
84d28b4e
...
@@ -5,6 +5,13 @@ import io
...
@@ -5,6 +5,13 @@ import io
import
pickle
import
pickle
import
sys
import
sys
class
UnseekableIO
(
io
.
FileIO
):
def
tell
(
self
):
raise
io
.
UnsupportedOperation
def
seek
(
self
,
*
args
,
**
kwargs
):
raise
io
.
UnsupportedOperation
def
byteswap2
(
data
):
def
byteswap2
(
data
):
a
=
array
.
array
(
'h'
)
a
=
array
.
array
(
'h'
)
a
.
frombytes
(
data
)
a
.
frombytes
(
data
)
...
@@ -129,6 +136,61 @@ class AudioWriteTests(AudioTests):
...
@@ -129,6 +136,61 @@ class AudioWriteTests(AudioTests):
self
.
assertEqual
(
testfile
.
read
(
13
),
b'ababagalamaga'
)
self
.
assertEqual
(
testfile
.
read
(
13
),
b'ababagalamaga'
)
self
.
check_file
(
testfile
,
self
.
nframes
,
self
.
frames
)
self
.
check_file
(
testfile
,
self
.
nframes
,
self
.
frames
)
def
test_unseekable_read
(
self
):
f
=
self
.
create_file
(
TESTFN
)
f
.
setnframes
(
self
.
nframes
)
f
.
writeframes
(
self
.
frames
)
f
.
close
()
with
UnseekableIO
(
TESTFN
,
'rb'
)
as
testfile
:
self
.
check_file
(
testfile
,
self
.
nframes
,
self
.
frames
)
def
test_unseekable_write
(
self
):
with
UnseekableIO
(
TESTFN
,
'wb'
)
as
testfile
:
f
=
self
.
create_file
(
testfile
)
f
.
setnframes
(
self
.
nframes
)
f
.
writeframes
(
self
.
frames
)
f
.
close
()
self
.
check_file
(
TESTFN
,
self
.
nframes
,
self
.
frames
)
def
test_unseekable_incompleted_write
(
self
):
with
UnseekableIO
(
TESTFN
,
'wb'
)
as
testfile
:
testfile
.
write
(
b'ababagalamaga'
)
f
=
self
.
create_file
(
testfile
)
f
.
setnframes
(
self
.
nframes
+
1
)
try
:
f
.
writeframes
(
self
.
frames
)
except
OSError
:
pass
try
:
f
.
close
()
except
OSError
:
pass
with
open
(
TESTFN
,
'rb'
)
as
testfile
:
self
.
assertEqual
(
testfile
.
read
(
13
),
b'ababagalamaga'
)
self
.
check_file
(
testfile
,
self
.
nframes
+
1
,
self
.
frames
)
def
test_unseekable_overflowed_write
(
self
):
with
UnseekableIO
(
TESTFN
,
'wb'
)
as
testfile
:
testfile
.
write
(
b'ababagalamaga'
)
f
=
self
.
create_file
(
testfile
)
f
.
setnframes
(
self
.
nframes
-
1
)
try
:
f
.
writeframes
(
self
.
frames
)
except
OSError
:
pass
try
:
f
.
close
()
except
OSError
:
pass
with
open
(
TESTFN
,
'rb'
)
as
testfile
:
self
.
assertEqual
(
testfile
.
read
(
13
),
b'ababagalamaga'
)
framesize
=
self
.
nchannels
*
self
.
sampwidth
self
.
check_file
(
testfile
,
self
.
nframes
-
1
,
self
.
frames
[:
-
framesize
])
class
AudioTestsWithSourceFile
(
AudioTests
):
class
AudioTestsWithSourceFile
(
AudioTests
):
...
...
Lib/test/test_aifc.py
View file @
84d28b4e
...
@@ -8,10 +8,14 @@ import struct
...
@@ -8,10 +8,14 @@ import struct
import
aifc
import
aifc
class
AifcPCM8Test
(
audiotests
.
AudioWriteTests
,
class
AifcTest
(
audiotests
.
AudioWriteTests
,
audiotests
.
AudioTestsWithSourceFile
,
audiotests
.
AudioTestsWithSourceFile
):
unittest
.
TestCase
):
module
=
aifc
module
=
aifc
close_fd
=
True
test_unseekable_read
=
None
class
AifcPCM8Test
(
AifcTest
,
unittest
.
TestCase
):
sndfilename
=
'pluck-pcm8.aiff'
sndfilename
=
'pluck-pcm8.aiff'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -26,13 +30,9 @@ class AifcPCM8Test(audiotests.AudioWriteTests,
...
@@ -26,13 +30,9 @@ class AifcPCM8Test(audiotests.AudioWriteTests,
11FA 3EFB BCFC 66FF CF04 4309 C10E 5112 EE17 8216 7F14 8012
\
11FA 3EFB BCFC 66FF CF04 4309 C10E 5112 EE17 8216 7F14 8012
\
490E 520D EF0F CE0F E40C 630A 080A 2B0B 510E 8B11 B60E 440A
\
490E 520D EF0F CE0F E40C 630A 080A 2B0B 510E 8B11 B60E 440A
\
"""
)
"""
)
close_fd
=
True
class
AifcPCM16Test
(
audiotests
.
AudioWriteTests
,
class
AifcPCM16Test
(
AifcTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
aifc
sndfilename
=
'pluck-pcm16.aiff'
sndfilename
=
'pluck-pcm16.aiff'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -49,13 +49,9 @@ class AifcPCM16Test(audiotests.AudioWriteTests,
...
@@ -49,13 +49,9 @@ class AifcPCM16Test(audiotests.AudioWriteTests,
EEE21753 82071665 7FFF1443 8004128F 49A20EAF 52BB0DBA EFB40F60 CE3C0FBF
\
EEE21753 82071665 7FFF1443 8004128F 49A20EAF 52BB0DBA EFB40F60 CE3C0FBF
\
E4B30CEC 63430A5C 08C80A20 2BBB0B08 514A0E43 8BCF1139 B6F60EEB 44120A5E
\
E4B30CEC 63430A5C 08C80A20 2BBB0B08 514A0E43 8BCF1139 B6F60EEB 44120A5E
\
"""
)
"""
)
close_fd
=
True
class
AifcPCM24Test
(
audiotests
.
AudioWriteTests
,
class
AifcPCM24Test
(
AifcTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
aifc
sndfilename
=
'pluck-pcm24.aiff'
sndfilename
=
'pluck-pcm24.aiff'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -78,13 +74,9 @@ class AifcPCM24Test(audiotests.AudioWriteTests,
...
@@ -78,13 +74,9 @@ class AifcPCM24Test(audiotests.AudioWriteTests,
E4B49C0CEA2D 6344A80A5A7C 08C8FE0A1FFE 2BB9860B0A0E
\
E4B49C0CEA2D 6344A80A5A7C 08C8FE0A1FFE 2BB9860B0A0E
\
51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48
\
51486F0E44E1 8BCC64113B05 B6F4EC0EEB36 4413170A5B48
\
"""
)
"""
)
close_fd
=
True
class
AifcPCM32Test
(
audiotests
.
AudioWriteTests
,
class
AifcPCM32Test
(
AifcTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
aifc
sndfilename
=
'pluck-pcm32.aiff'
sndfilename
=
'pluck-pcm32.aiff'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -107,13 +99,9 @@ class AifcPCM32Test(audiotests.AudioWriteTests,
...
@@ -107,13 +99,9 @@ class AifcPCM32Test(audiotests.AudioWriteTests,
E4B49CC00CEA2D90 6344A8800A5A7CA0 08C8FE800A1FFEE0 2BB986C00B0A0E00
\
E4B49CC00CEA2D90 6344A8800A5A7CA0 08C8FE800A1FFEE0 2BB986C00B0A0E00
\
51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0
\
51486F800E44E190 8BCC6480113B0580 B6F4EC000EEB3630 441317800A5B48A0
\
"""
)
"""
)
close_fd
=
True
class
AifcULAWTest
(
audiotests
.
AudioWriteTests
,
class
AifcULAWTest
(
AifcTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
aifc
sndfilename
=
'pluck-ulaw.aifc'
sndfilename
=
'pluck-ulaw.aifc'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -132,13 +120,9 @@ class AifcULAWTest(audiotests.AudioWriteTests,
...
@@ -132,13 +120,9 @@ class AifcULAWTest(audiotests.AudioWriteTests,
"""
)
"""
)
if
sys
.
byteorder
!=
'big'
:
if
sys
.
byteorder
!=
'big'
:
frames
=
audiotests
.
byteswap2
(
frames
)
frames
=
audiotests
.
byteswap2
(
frames
)
close_fd
=
True
class
AifcALAWTest
(
audiotests
.
AudioWriteTests
,
class
AifcALAWTest
(
AifcTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
aifc
sndfilename
=
'pluck-alaw.aifc'
sndfilename
=
'pluck-alaw.aifc'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -157,7 +141,6 @@ class AifcALAWTest(audiotests.AudioWriteTests,
...
@@ -157,7 +141,6 @@ class AifcALAWTest(audiotests.AudioWriteTests,
"""
)
"""
)
if
sys
.
byteorder
!=
'big'
:
if
sys
.
byteorder
!=
'big'
:
frames
=
audiotests
.
byteswap2
(
frames
)
frames
=
audiotests
.
byteswap2
(
frames
)
close_fd
=
True
class
AifcMiscTest
(
audiotests
.
AudioTests
,
unittest
.
TestCase
):
class
AifcMiscTest
(
audiotests
.
AudioTests
,
unittest
.
TestCase
):
...
...
Lib/test/test_sunau.py
View file @
84d28b4e
...
@@ -5,10 +5,12 @@ import sys
...
@@ -5,10 +5,12 @@ import sys
import
sunau
import
sunau
class
SunauPCM8Test
(
audiotests
.
AudioWriteTests
,
class
SunauTest
(
audiotests
.
AudioWriteTests
,
audiotests
.
AudioTestsWithSourceFile
,
audiotests
.
AudioTestsWithSourceFile
):
unittest
.
TestCase
):
module
=
sunau
module
=
sunau
class
SunauPCM8Test
(
SunauTest
,
unittest
.
TestCase
):
sndfilename
=
'pluck-pcm8.au'
sndfilename
=
'pluck-pcm8.au'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -25,10 +27,7 @@ class SunauPCM8Test(audiotests.AudioWriteTests,
...
@@ -25,10 +27,7 @@ class SunauPCM8Test(audiotests.AudioWriteTests,
"""
)
"""
)
class
SunauPCM16Test
(
audiotests
.
AudioWriteTests
,
class
SunauPCM16Test
(
SunauTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
sunau
sndfilename
=
'pluck-pcm16.au'
sndfilename
=
'pluck-pcm16.au'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -47,10 +46,7 @@ class SunauPCM16Test(audiotests.AudioWriteTests,
...
@@ -47,10 +46,7 @@ class SunauPCM16Test(audiotests.AudioWriteTests,
"""
)
"""
)
class
SunauPCM32Test
(
audiotests
.
AudioWriteTests
,
class
SunauPCM32Test
(
SunauTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
sunau
sndfilename
=
'pluck-pcm32.au'
sndfilename
=
'pluck-pcm32.au'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -75,10 +71,7 @@ class SunauPCM32Test(audiotests.AudioWriteTests,
...
@@ -75,10 +71,7 @@ class SunauPCM32Test(audiotests.AudioWriteTests,
"""
)
"""
)
class
SunauULAWTest
(
audiotests
.
AudioWriteTests
,
class
SunauULAWTest
(
SunauTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
sunau
sndfilename
=
'pluck-ulaw.au'
sndfilename
=
'pluck-ulaw.au'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
...
Lib/test/test_wave.py
View file @
84d28b4e
...
@@ -5,10 +5,15 @@ import sys
...
@@ -5,10 +5,15 @@ import sys
import
wave
import
wave
class
WavePCM8Test
(
audiotests
.
AudioWriteTests
,
class
WaveTest
(
audiotests
.
AudioWriteTests
,
audiotests
.
AudioTestsWithSourceFile
,
audiotests
.
AudioTestsWithSourceFile
):
unittest
.
TestCase
):
module
=
wave
module
=
wave
test_unseekable_write
=
None
test_unseekable_overflowed_write
=
None
test_unseekable_incompleted_write
=
None
class
WavePCM8Test
(
WaveTest
,
unittest
.
TestCase
):
sndfilename
=
'pluck-pcm8.wav'
sndfilename
=
'pluck-pcm8.wav'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -25,10 +30,7 @@ class WavePCM8Test(audiotests.AudioWriteTests,
...
@@ -25,10 +30,7 @@ class WavePCM8Test(audiotests.AudioWriteTests,
"""
)
"""
)
class
WavePCM16Test
(
audiotests
.
AudioWriteTests
,
class
WavePCM16Test
(
WaveTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
wave
sndfilename
=
'pluck-pcm16.wav'
sndfilename
=
'pluck-pcm16.wav'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -55,10 +57,7 @@ class WavePCM16Test(audiotests.AudioWriteTests,
...
@@ -55,10 +57,7 @@ class WavePCM16Test(audiotests.AudioWriteTests,
class
WavePCM24Test
(
audiotests
.
AudioWriteTests
,
class
WavePCM24Test
(
WaveTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
wave
sndfilename
=
'pluck-pcm24.wav'
sndfilename
=
'pluck-pcm24.wav'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
@@ -85,10 +84,7 @@ class WavePCM24Test(audiotests.AudioWriteTests,
...
@@ -85,10 +84,7 @@ class WavePCM24Test(audiotests.AudioWriteTests,
frames
=
audiotests
.
byteswap3
(
frames
)
frames
=
audiotests
.
byteswap3
(
frames
)
class
WavePCM32Test
(
audiotests
.
AudioWriteTests
,
class
WavePCM32Test
(
WaveTest
,
unittest
.
TestCase
):
audiotests
.
AudioTestsWithSourceFile
,
unittest
.
TestCase
):
module
=
wave
sndfilename
=
'pluck-pcm32.wav'
sndfilename
=
'pluck-pcm32.wav'
sndfilenframes
=
3307
sndfilenframes
=
3307
nchannels
=
2
nchannels
=
2
...
...
Misc/NEWS
View file @
84d28b4e
...
@@ -32,6 +32,8 @@ Core and Builtins
...
@@ -32,6 +32,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #19623: Fixed writing to unseekable files in the aifc module.
- Issue #17919: select.poll.register() again works with poll.POLLNVAL on AIX.
- Issue #17919: select.poll.register() again works with poll.POLLNVAL on AIX.
Fixed integer overflow in the eventmask parameter.
Fixed integer overflow in the eventmask parameter.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment