On Mon, Jul 27, 2015 at 2:44 PM, Luca Barbato <[email protected]> wrote: > On 27/07/15 15:35, Vittorio Giovara wrote: >> On Sat, Jul 25, 2015 at 4:59 PM, Luca Barbato <[email protected]> wrote: >>> And restrict the string to ascii text. >>> >>> CC: [email protected] >>> --- >>> >>> libavcodec/h264_sei.c | 53 >>> +++++++++++++++++++++++++++++++++++++++++---------- >>> 1 file changed, 43 insertions(+), 10 deletions(-) >>> >>> diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c >>> index 1f3844b..7a5c9d6 100644 >>> --- a/libavcodec/h264_sei.c >>> +++ b/libavcodec/h264_sei.c >>> @@ -191,24 +191,57 @@ static int decode_registered_user_data(H264Context >>> *h, int size) >>> return 0; >>> } >>> >>> -static int decode_unregistered_user_data(H264Context *h, int size) >>> +static const uint8_t x264_version_uuid[] = { >>> + 0xdc, 0x45, 0xe9, 0xbd, 0xe6, 0xd9, 0x48, 0xb7, >>> + 0x96, 0x2c, 0xd8, 0x20, 0xd9, 0x23, 0xee, 0xef >>> +}; >>> + >>> +static int decode_x264_version(H264Context *h, int size) >>> { >>> - uint8_t user_data[16 + 256]; >>> int e, build, i; >>> + uint8_t x264_string[256]; >>> >>> - if (size < 16) >>> - return AVERROR_INVALIDDATA; >>> >>> - for (i = 0; i < sizeof(user_data) - 1 && i < size; i++) >>> - user_data[i] = get_bits(&h->gb, 8); >>> + for (i = 0; i < size && i < sizeof(x264_string) - 1; i++) >>> + x264_string[i] = get_bits(&h->gb, 8) & 0x7f; >>> + >>> + x264_string[i] = 0; >>> >>> - user_data[i] = 0; >>> - e = sscanf(user_data + 16, "x264 - core %d", &build); >>> + e = sscanf(x264_string, "x264 - core %d", &build); >>> if (e == 1 && build > 0) >>> - h->x264_build = build; >>> + h->x264_build = build; >>> >>> if (h->avctx->debug & FF_DEBUG_BUGS) >>> - av_log(h->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data + >>> 16); >>> + av_log(h->avctx, AV_LOG_DEBUG, "x264 version string:\"%s\"\n", >>> x264_string + 16); >>> + >>> + for (; i < size; i++) >>> + skip_bits(&h->gb, 8); >>> + >>> + return 0; >>> +} >>> + >>> +static int decode_unregistered_user_data(H264Context *h, int size) >>> +{ >>> + int i; >>> + uint8_t uuid[16]; >>> + >>> + if (size < 16) >>> + return AVERROR_INVALIDDATA; >>> + >>> + for (i = 0; i < 16; i++) >>> + uuid[i] = get_bits(&h->gb, 8); >>> + >>> + av_log(h->avctx, AV_LOG_DEBUG, "uuid 0x%02x 0x%02x 0x%02x 0x%02x " >>> + "0x%02x 0x%02x 0x%02x 0x%02x " >>> + "0x%02x 0x%02x 0x%02x 0x%02x " >>> + "0x%02x 0x%02x 0x%02x 0x%02x\n", >>> + uuid[0], uuid[1], uuid[2], uuid[3], >>> + uuid[4], uuid[5], uuid[6], uuid[7], >>> + uuid[8], uuid[9], uuid[10], uuid[11], >>> + uuid[12], uuid[13], uuid[14], uuid[15]); >>> + >>> + if (!memcmp(uuid, x264_version_uuid, 16)) >>> + return decode_x264_version(h, size - 16); >>> >>> for (; i < size; i++) >>> skip_bits(&h->gb, 8); >>> -- >> >> why is this needed? >> > > Make the parsing a little more robust and prevent printing garbage. > > I'm not exactly fond of using & 127 though.
mind mentioning this in the log? > Probably I should rework the patch not to use sscanf to begin with. > (printing garbage is a real concern thought?) as you prefer -- Vittorio _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
