[Python-checkins] CVS: python/dist/src/Modules audioop.c,1.45,1.46

Tim Peters tim_one@users.sourceforge.net
2001年12月05日 14:30:23 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv30778/python/Modules
Modified Files:
	audioop.c 
Log Message:
audioop_ratecv(): I left a potentially unsafe multiply unchecked
yesterday -- repair that. Also renamed the silly size_times_nchannels
to bytes_per_frame.
Index: audioop.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/audioop.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** audioop.c	2001年12月05日 06:05:07	1.45
--- audioop.c	2001年12月05日 22:30:21	1.46
***************
*** 904,908 ****
 	int chan, d, *prev_i, *cur_i, cur_o;
 	PyObject *state, *samps, *str, *rv = NULL;
! 	int size_times_nchannels;
 
 	weightA = 1;
--- 904,908 ----
 	int chan, d, *prev_i, *cur_i, cur_o;
 	PyObject *state, *samps, *str, *rv = NULL;
! 	int bytes_per_frame;
 
 	weightA = 1;
***************
*** 919,922 ****
--- 919,931 ----
 		return NULL;
 	}
+ 	bytes_per_frame = size * nchannels;
+ 	if (bytes_per_frame / nchannels != size) {
+ 		/* This overflow test is rigorously correct because
+ 		 both multiplicands are >= 1. Use the argument names
+ 		 from the docs for the error msg. */
+ 		PyErr_SetString(PyExc_OverflowError,
+ 		 "width * nchannels too big for a C int");
+ 		return NULL;
+ 	}
 	if (weightA < 1 || weightB < 0) {
 		PyErr_SetString(AudioopError,
***************
*** 924,928 ****
 		return NULL;
 	}
! 	if (len % (size * nchannels) != 0) {
 		PyErr_SetString(AudioopError, "not a whole number of frames");
 		return NULL;
--- 933,937 ----
 		return NULL;
 	}
! 	if (len % bytes_per_frame != 0) {
 		PyErr_SetString(AudioopError, "not a whole number of frames");
 		return NULL;
***************
*** 944,957 ****
 	}
 
! 	size_times_nchannels = size * nchannels;
! 	if (size_times_nchannels / nchannels != size) {
! 		/* This overflow test is rigorously correct because
! 		 both multiplicands are >= 1. Use the argument names
! 		 from the docs for the error msg. */
! 		PyErr_SetString(PyExc_OverflowError,
! 		 "width * nchannels too big for a C int");
! 		goto exit;
! 	}
! 	len /= size_times_nchannels;	/* # of frames */
 
 	if (state == Py_None) {
--- 953,957 ----
 	}
 
! 	len /= bytes_per_frame;	/* # of frames */
 
 	if (state == Py_None) {
***************
*** 981,985 ****
 		/* There are len input frames, so we need (mathematically)
 		 ceiling(len*outrate/inrate) output frames, and each frame
! 		 requires size_times_nchannels bytes. Computing this
 		 without spurious overflow is the challenge. */
 		int ceiling; /* the number of output frames, eventually */
--- 981,985 ----
 		/* There are len input frames, so we need (mathematically)
 		 ceiling(len*outrate/inrate) output frames, and each frame
! 		 requires bytes_per_frame bytes. Computing this
 		 without spurious overflow is the challenge. */
 		int ceiling; /* the number of output frames, eventually */
***************
*** 1013,1018 ****
 			goto exit;
 		}
! 		nbytes = ceiling * size_times_nchannels;
! 		if (nbytes / size_times_nchannels != ceiling) {
 			PyErr_SetString(PyExc_MemoryError,
 				"not enough memory for output buffer");
--- 1013,1018 ----
 			goto exit;
 		}
! 		nbytes = ceiling * bytes_per_frame;
! 		if (nbytes / bytes_per_frame != ceiling) {
 			PyErr_SetString(PyExc_MemoryError,
 				"not enough memory for output buffer");

AltStyle によって変換されたページ (->オリジナル) /