Update of /cvsroot/mplayer/main In directory mail:/var/tmp.root/cvs-serv15772 Modified Files: spudec.c Log Message: avoids malloc()ing a negative number (== very big size_t) some vobsub's trigger this case and cause a: "MPlayer interrupted by signal 2 in module: decode_video" Index: spudec.c =================================================================== RCS file: /cvsroot/mplayer/main/spudec.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- spudec.c 28 May 2002 02:16:01 -0000 1.30 +++ spudec.c 29 May 2002 00:32:52 -0000 1.31 @@ -133,13 +133,21 @@ unsigned int first_y, last_y; unsigned char *image; unsigned char *aimage; + for (fy = 0; fy < this->image_size && !this->aimage[fy]; fy++); for (ly = this->stride * this->height-1; ly && !this->aimage[ly]; ly--); first_y = fy / this->stride; last_y = ly / this->stride; //printf("first_y: %d, last_y: %d\n", first_y, last_y); this->start_row += first_y; - this->height = last_y - first_y +1; + + // Some subtitles trigger this condition + if (last_y + 1 > first_y ) { + this->height = last_y - first_y +1; + } else { + this->height = 0; + } + //printf("new h %d new start %d (sz %d st %d)---\n\n", this->height, this->start_row, this->image_size, this->stride); image = malloc(2 * this->stride * this->height); if(image){ @@ -150,9 +158,12 @@ free(this->image); this->image = image; this->aimage = aimage; + } else { + // We'll get NULL if 0 byte is requested and it's not an error + if (this->stride && this->height ) { + fprintf(stderr,"Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height); + } } - else - perror("Fatal: update_spu: malloc"); } static void spudec_process_data(spudec_handle_t *this)
On Wed, May 29, 2002 at 02:33:06AM +0200, pl wrote:
+ } else { + // We'll get NULL if 0 byte is requested and it's not an error + if (this->stride && this->height ) { + fprintf(stderr,"Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height); + }
malloc will return a pointer != NULL if 0 bytes is requested (and the allocation did succeed). A simple test program shows this. The Linux manual page isn't very clear on the issue; the OpenBSD one describes it though (http://www.openbsd.org/cgi-bin/man.cgi?query=malloc&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html). / Fredrik
On Wed, May 29, 2002 at 10:25:19AM +0200, Fredrik Kuivinen wrote:
On Wed, May 29, 2002 at 02:33:06AM +0200, pl wrote:
+ } else { + // We'll get NULL if 0 byte is requested and it's not an error + if (this->stride && this->height ) { + fprintf(stderr,"Fatal: update_spu: malloc requested %d bytes\n", 2 * this->stride * this->height); + }
malloc will return a pointer != NULL if 0 bytes is requested (and the allocation did succeed). A simple test program shows this. The Linux manual page isn't very clear on the issue; the OpenBSD one describes it though (http://www.openbsd.org/cgi-bin/man.cgi?query=malloc&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html).
I'd say the page is not even very clear... it's really misleading :) Quoting malloc man page on nux: "If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned." Thanks to these imprecisions I guess both flavors probablyexist with different linux/malloc libs etc... After rereading the code it should be ok (handled by the other 'if' branch). Anyway I guess it would be better to avoid allocating 0 byte :) -- Best regards, pl
participants (3)
-
Fredrik Kuivinen -
pl -
pl