On 15/01/15 12:30, Martin Storsjö wrote:
On Wed, 14 Jan 2015, Luca Barbato wrote:
Support only streams with Content-Length.
---
That's probably ok as a first version of it. The ironic thing is that
the mpjpeg streams that our muxer produces don't include any
Content-Length.
Should be easy to fix =)
We already have ff_get_line - could this be adapted to use that instead?
I would consider 0
+static int split_tag_value(char **tag, char **value, char *line)
+{
+ char *p = line;
+
+ while (*p != '\0' && *p != ':')
+ p++;
Isn't this pretty much what strchr does, or it could at least be changed
to use strchr?
+ if (*p != ':')
+ return AVERROR_INVALIDDATA;
+
+ *p = '\0';
+ *tag = line;
+
+ p++;
+
+ while (av_isspace(*p))
+ p++;
+
+ *value = p;
+
+ return 0;
+}
+
+static int check_content_type(char *line)
+{
+ char *tag, *value;
+ int ret = split_tag_value(&tag, &value, line);
+
+ if (ret < 0)
+ return ret;
+
+ if (av_strcasecmp(tag, "Content-type") ||
+ av_strcasecmp(value, "image/jpeg"))
+ return AVERROR_INVALIDDATA;
+
+ return 0;
+}
+
+static int mpjpeg_read_probe(AVProbeData *p)
+{
+ AVIOContext *pb;
+ char line[128] = { 0 };
+ int ret;
+
+ pb = avio_alloc_context(p->buf, p->buf_size, 0, NULL, NULL, NULL,
NULL);
+ if (!pb)
+ return AVERROR(ENOMEM);
+
+ while (!pb->eof_reached) {
+ ret = get_line(pb, line, sizeof(line));
+ if (ret < 0)
+ break;
+
+ ret = check_content_type(line);
+ if (!ret)
+ return AVPROBE_SCORE_MAX;
+ }
This leaks the allocated AVIOContext.
Fixed
Also, even though this in itself isn't a very heavy operation, it would
still be executed on every single file open. Is there some simple rough
test that could be executed at the start, that could return sooner
(before even trying to allocate anything) for clearly non-matching data?
+ if (strncmp(boundary, "--", 2))
+ return AVERROR_INVALIDDATA;
Something on the lines of
if (p->buf_size < 2 || p->buf[0] != '-' || p->buf[1] != '-')
return 0;
Here we seem to require that the first two bytes of the whole stream
should be "--" - this would be an excellent first check in the probe
function, to avoid the more expensive parsing until that matches.
This seems to assume that content type and content length always come in
this particular order
Yes, might be a good idea to change it to something like
while (found tag) {
if (!found_content_type)
found_content_type = check_content_type(...)
if (!found_content_lenght)
found_content_lenght = check_....
}
if (!found || !found)
fail
lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel