[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50735] trunk/blender/source/blender/ editors/space_sequencer/sequencer_scopes.c: fix buffer overrun in make_histogram_view_from_ibuf_byte(), use define for buffer size so this wont happen again.

Campbell Barton ideasman42 at gmail.com
Wed Sep 19 02:56:10 CEST 2012


Revision: 50735
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50735
Author:   campbellbarton
Date:     2012-09-19 00:56:09 +0000 (Wed, 19 Sep 2012)
Log Message:
-----------
fix buffer overrun in make_histogram_view_from_ibuf_byte(), use define for buffer size so this wont happen again.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_sequencer/sequencer_scopes.c

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_scopes.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_scopes.c	2012-09-19 00:09:14 UTC (rev 50734)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_scopes.c	2012-09-19 00:56:09 UTC (rev 50735)
@@ -449,6 +449,8 @@
 	}
 }
 
+#define HIS_STEPS 512
+
 static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf)
 {
 	ImBuf *rval = IMB_allocImBuf(515, 128, 32, IB_rect);
@@ -456,13 +458,13 @@
 	unsigned int n;
 	unsigned char *src = (unsigned char *) ibuf->rect;
 
-	unsigned int bins[3][256];
+	unsigned int bins[3][HIS_STEPS];
 
 	memset(bins, 0, sizeof(bins));
 
 	#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256)
 	for (y = 0; y < ibuf->y; y++) {
-		unsigned int cur_bins[3][512];
+		unsigned int cur_bins[3][HIS_STEPS];
 
 		memset(cur_bins, 0, sizeof(cur_bins));
 
@@ -477,7 +479,7 @@
 		#pragma omp critical
 		{
 			int i;
-			for (i = 0; i < 512; i++) {
+			for (i = 0; i < HIS_STEPS; i++) {
 				bins[0][i] += cur_bins[0][i];
 				bins[1][i] += cur_bins[1][i];
 				bins[2][i] += cur_bins[2][i];
@@ -487,7 +489,7 @@
 
 	n = 0;
 	for (c = 0; c < 3; c++) {
-		for (x = 0; x < 256; x++) {
+		for (x = 0; x < HIS_STEPS; x++) {
 			if (bins[c][x] > n) {
 				n = bins[c][x];
 			}
@@ -495,7 +497,7 @@
 	}
 
 	for (c = 0; c < 3; c++) {
-		for (x = 0; x < 256; x++) {
+		for (x = 0; x < HIS_STEPS; x++) {
 			draw_histogram_bar(rval, x * 2 + 1, ((float) bins[c][x]) / n, c);
 			draw_histogram_bar(rval, x * 2 + 2, ((float) bins[c][x]) / n, c);
 		}
@@ -524,13 +526,13 @@
 	int n, c, x, y;
 	float *src = ibuf->rect_float;
 
-	unsigned int bins[3][512];
+	unsigned int bins[3][HIS_STEPS];
 
 	memset(bins, 0, sizeof(bins));
 
 	#pragma omp parallel for shared(bins, src, ibuf) private(x, y) if (ibuf->y >= 256)
 	for (y = 0; y < ibuf->y; y++) {
-		unsigned int cur_bins[3][512];
+		unsigned int cur_bins[3][HIS_STEPS];
 
 		memset(cur_bins, 0, sizeof(cur_bins));
 
@@ -545,7 +547,7 @@
 		#pragma omp critical
 		{
 			int i;
-			for (i = 0; i < 512; i++) {
+			for (i = 0; i < HIS_STEPS; i++) {
 				bins[0][i] += cur_bins[0][i];
 				bins[1][i] += cur_bins[1][i];
 				bins[2][i] += cur_bins[2][i];
@@ -558,14 +560,14 @@
 
 	n = 0;
 	for (c = 0; c < 3; c++) {
-		for (x = 0; x < 512; x++) {
+		for (x = 0; x < HIS_STEPS; x++) {
 			if (bins[c][x] > n) {
 				n = bins[c][x];
 			}
 		}
 	}
 	for (c = 0; c < 3; c++) {
-		for (x = 0; x < 512; x++) {
+		for (x = 0; x < HIS_STEPS; x++) {
 			draw_histogram_bar(rval, x + 1, (float) bins[c][x] / n, c);
 		}
 	}
@@ -575,6 +577,8 @@
 	return rval;
 }
 
+#undef HIS_STEPS
+
 ImBuf *make_histogram_view_from_ibuf(ImBuf *ibuf)
 {
 	if (ibuf->rect_float) {




More information about the Bf-blender-cvs mailing list