Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(143735)

Side by Side Diff: Lib/test/test_audioop.py

Issue 24456: audioop.adpcm2lin Buffer Over-read
Patch Set: Created 4 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/audioop.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import audioop 1 import audioop
2 import sys 2 import sys
3 import unittest 3 import unittest
4 4
5 def pack(width, data): 5 def pack(width, data):
6 return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data) 6 return b''.join(v.to_bytes(width, sys.byteorder, signed=True) for v in data)
7 7
8 def unpack(width, data): 8 def unpack(width, data):
9 return [int.from_bytes(data[i: i + width], sys.byteorder, signed=True) 9 return [int.from_bytes(data[i: i + width], sys.byteorder, signed=True)
10 for i in range(0, len(data), width)] 10 for i in range(0, len(data), width)]
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 # Very cursory test 267 # Very cursory test
268 for w in 1, 2, 3, 4: 268 for w in 1, 2, 3, 4:
269 self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None), 269 self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
270 (b'\0' * 5, (0, 0))) 270 (b'\0' * 5, (0, 0)))
271 271
272 def test_invalid_adpcm_state(self): 272 def test_invalid_adpcm_state(self):
273 # state must be a tuple or None, not an integer 273 # state must be a tuple or None, not an integer
274 self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555) 274 self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555)
275 self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555) 275 self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555)
276 # Issues #24456, #24457: index out of range
277 self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0, -1))
278 self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0, 89))
279 self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0, -1))
280 self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0, 89))
281 # value out of range
282 self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (-0x8001, 0))
283 self.assertRaises(ValueError, audioop.adpcm2lin, b'\0', 1, (0x8000, 0))
284 self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (-0x8001, 0))
285 self.assertRaises(ValueError, audioop.lin2adpcm, b'\0', 1, (0x8000, 0))
276 286
277 def test_lin2alaw(self): 287 def test_lin2alaw(self):
278 self.assertEqual(audioop.lin2alaw(datas[1], 1), 288 self.assertEqual(audioop.lin2alaw(datas[1], 1),
279 b'\xd5\x87\xa4\x24\xaa\x2a\x5a') 289 b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
280 self.assertEqual(audioop.lin2alaw(bytearray(datas[1]), 1), 290 self.assertEqual(audioop.lin2alaw(bytearray(datas[1]), 1),
281 b'\xd5\x87\xa4\x24\xaa\x2a\x5a') 291 b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
282 self.assertEqual(audioop.lin2alaw(memoryview(datas[1]), 1), 292 self.assertEqual(audioop.lin2alaw(memoryview(datas[1]), 1),
283 b'\xd5\x87\xa4\x24\xaa\x2a\x5a') 293 b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
284 for w in 2, 3, 4: 294 for w in 2, 3, 4:
285 self.assertEqual(audioop.lin2alaw(datas[w], w), 295 self.assertEqual(audioop.lin2alaw(datas[w], w),
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 def test_wrongsize(self): 552 def test_wrongsize(self):
543 data = b'abcdefgh' 553 data = b'abcdefgh'
544 state = None 554 state = None
545 for size in (-1, 0, 5, 1024): 555 for size in (-1, 0, 5, 1024):
546 self.assertRaises(audioop.error, audioop.ulaw2lin, data, size) 556 self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
547 self.assertRaises(audioop.error, audioop.alaw2lin, data, size) 557 self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
548 self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, stat e) 558 self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, stat e)
549 559
550 if __name__ == '__main__': 560 if __name__ == '__main__':
551 unittest.main() 561 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | Modules/audioop.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+