[pywin32-checkins] pywin32/com/win32com/test testStreams.py, 1.4, 1.5
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-07-03 21:10:25
|
Update of /cvsroot/pywin32/pywin32/com/win32com/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30281/com/win32com/test Modified Files: testStreams.py Log Message: Add Seek, and test for a buffer overflow Index: testStreams.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testStreams.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** testStreams.py 10 Nov 2003 00:49:29 -0000 1.4 --- testStreams.py 3 Jul 2007 21:10:26 -0000 1.5 *************** *** 30,34 **** class Stream: ! _public_methods_ = [ 'Read', 'Write' ] _com_interfaces_ = [ pythoncom.IID_IStream ] --- 30,34 ---- class Stream: ! _public_methods_ = [ 'Read', 'Write', 'Seek' ] _com_interfaces_ = [ pythoncom.IID_IStream ] *************** *** 47,50 **** --- 47,71 ---- return len(data) + def Seek(self, dist, origin): + if origin==pythoncom.STREAM_SEEK_SET: + self.index = dist + elif origin==pythoncom.STREAM_SEEK_CUR: + self.index = self.index + dist + elif origin==pythoncom.STREAM_SEEK_END: + self.index = len(self.data)+dist + else: + raise ValueError, 'Unknown Seek type: ' +str(origin) + if self.index < 0: + self.index = 0 + else: + self.index = min(self.index, len(self.data)) + return self.index + + class BadStream(Stream): + """ PyGStream::Read could formerly overflow buffer if the python implementation + returned more data than requested. + """ + def Read(self, amount): + return 'x'*(amount+1) class StreamTest(win32com.test.util.TestCase): *************** *** 52,57 **** --- 73,82 ---- if read_stream is None: read_stream = write_stream write_stream.Write(data) + read_stream.Seek(0, pythoncom.STREAM_SEEK_SET) got = read_stream.Read(len(data)) self.assertEqual(data, got) + read_stream.Seek(1, pythoncom.STREAM_SEEK_SET) + got = read_stream.Read(len(data)-2) + self.assertEqual(data[1:-1], got) def testit(self): *************** *** 83,86 **** --- 108,116 ---- self.assertEqual(s.data, mydata) + ## check for buffer overflow in Read method + badstream = BadStream('Check for buffer overflow') + badstream2 = win32com.server.util.wrap(badstream, pythoncom.IID_IStream) + self.assertRaises(pythoncom.com_error, badstream2.Read, 10) + if __name__=='__main__': unittest.main() |