[FFmpeg-devel] [PATCH 03/11] Implement av_get_codec_tag_string() and use it in ffprobe.
Stefano Sabatini
stefano.sabatini-lala
Tue Jun 1 11:38:22 CEST 2010
On date Wednesday 2010-05-26 21:52:08 +0200, Michael Niedermayer encoded:
> On Wed, May 26, 2010 at 09:40:44PM +0200, Stefano Sabatini wrote:
> >
> > size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_t
> > {
> > size_t i, ret = 0;
> > *buf = 0;
> > for (i = 0; i < 4; i++) {
> > const char *tmpl = isprint(codec_tag&0xFF) ? "%c" : "[%d]";
> > ret += av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);
> > codec_tag>>=8;
> > }
> > return ret;
> > }
> >
> > keep adding to ret the value of the string and the appended string,
> > even using:
> > ret = av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);
> >
> > doesn't work if the string is too short.
> >
> > So attached again the first version (I'll drop the test in the commit).
>
> this version overwrites the end of the array
> i would prefer av_strlcatf() be used
Could you elaborate on that? To me this implementation looks perfectly
safe, here it is the result of the test:
i:0 ret:9 tag:???93UwW????
i:1 ret:9 tag:
i:2 ret:9 tag:Y
i:3 ret:9 tag:Y4
i:4 ret:9 tag:Y4[
i:5 ret:9 tag:Y4[1
i:6 ret:9 tag:Y4[11
i:7 ret:9 tag:Y4[11]
i:8 ret:9 tag:Y4[11][
i:9 ret:9 tag:Y4[11][8
i:10 ret:9 tag:Y4[11][8]
i:11 ret:9 tag:Y4[11][8]
i:12 ret:9 tag:Y4[11][8]
i:13 ret:9 tag:Y4[11][8]
i:14 ret:9 tag:Y4[11][8]
i:15 ret:9 tag:Y4[11][8]
Note that null termination is demanded by ISO C99.
With av_strlcatf() I would have to jump through additional hoops, as
it returns the lenght of the complete string, not only of the added
len, with no gain.
Also av_strlcatf() uses snprintf() internally, so it is equivalent
security-wise.
Regards.
--
FFmpeg = Funny and Forgiving Magical Philosofic Elastic Geek
More information about the ffmpeg-devel
mailing list