mirror of https://github.com/mpv-player/mpv
Fix crash for gif images that have Top or Left set
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@21900 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
eb2b0bc2a7
commit
e52420a9fe
|
@ -21,6 +21,7 @@ typedef struct {
|
||||||
int current_pts;
|
int current_pts;
|
||||||
unsigned char *palette;
|
unsigned char *palette;
|
||||||
GifFileType *gif;
|
GifFileType *gif;
|
||||||
|
int w, h;
|
||||||
} gif_priv_t;
|
} gif_priv_t;
|
||||||
|
|
||||||
#define GIF_SIGNATURE (('G' << 16) | ('I' << 8) | 'F')
|
#define GIF_SIGNATURE (('G' << 16) | ('I' << 8) | 'F')
|
||||||
|
@ -104,7 +105,7 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
len = gif->Image.Width * gif->Image.Height;
|
len = gif->Image.Width * gif->Image.Height;
|
||||||
dp = new_demux_packet(len);
|
dp = new_demux_packet(priv->w * priv->h);
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
memset(buf, 0, len);
|
memset(buf, 0, len);
|
||||||
memset(dp->buffer, 0, len);
|
memset(dp->buffer, 0, len);
|
||||||
|
@ -121,6 +122,10 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
|
||||||
int y;
|
int y;
|
||||||
int cnt = effective_map->ColorCount;
|
int cnt = effective_map->ColorCount;
|
||||||
if (cnt > 256) cnt = 256;
|
if (cnt > 256) cnt = 256;
|
||||||
|
int l = FFMIN(gif->Image.Left, priv->w);
|
||||||
|
int t = FFMIN(gif->Image.Top, priv->h);
|
||||||
|
int w = FFMIN(gif->Image.Width, priv->w - l);
|
||||||
|
int h = FFMIN(gif->Image.Height, priv->h - t);
|
||||||
|
|
||||||
// copy the palette
|
// copy the palette
|
||||||
for (y = 0; y < cnt; y++) {
|
for (y = 0; y < cnt; y++) {
|
||||||
|
@ -130,14 +135,13 @@ static int demux_gif_fill_buffer(demuxer_t *demuxer, demux_stream_t *ds)
|
||||||
priv->palette[(y * 4) + 3] = 0;
|
priv->palette[(y * 4) + 3] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y = 0; y < gif->Image.Height; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
unsigned char *drow = dp->buffer;
|
unsigned char *drow = dp->buffer;
|
||||||
unsigned char *gbuf = buf + (y * gif->Image.Width);
|
unsigned char *gbuf = buf + (y * gif->Image.Width);
|
||||||
|
|
||||||
drow += gif->Image.Width * (y + gif->Image.Top);
|
drow += priv->w * (y + t) + l;
|
||||||
drow += gif->Image.Left;
|
|
||||||
|
|
||||||
memcpy(drow, gbuf, gif->Image.Width);
|
memcpy(drow, gbuf, w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +208,8 @@ static demuxer_t* demux_open_gif(demuxer_t* demuxer)
|
||||||
sh_video->bih->biBitCount = 8;
|
sh_video->bih->biBitCount = 8;
|
||||||
sh_video->bih->biPlanes = 2;
|
sh_video->bih->biPlanes = 2;
|
||||||
priv->palette = (unsigned char *)(sh_video->bih + 1);
|
priv->palette = (unsigned char *)(sh_video->bih + 1);
|
||||||
|
priv->w = sh_video->disp_w;
|
||||||
|
priv->h = sh_video->disp_h;
|
||||||
|
|
||||||
priv->gif = gif;
|
priv->gif = gif;
|
||||||
demuxer->priv = priv;
|
demuxer->priv = priv;
|
||||||
|
|
Loading…
Reference in New Issue