Esempio n. 1
0
static long check_opus_header(DB_FILE *in, ogg_sync_state *oy, const off_t offset, char **vendor)
{
    ogg_stream_state os;
    ogg_page og;
    const int64_t serial = init_read_stream(in, oy, &os, &og, offset, OPUSNAME);
    if (serial <= OGGEDIT_EOF)
        return serial;

    ogg_packet op;
    const long pages = read_packet(in, oy, &os, &og, &op, 1);
    ogg_stream_clear(&os);
    if (pages <= OGGEDIT_EOF)
        return pages;

    if (op.bytes > strlen(TAGMAGIC) && !memcmp(op.packet, TAGMAGIC, strlen(TAGMAGIC)))
        *vendor = parse_vendor(&op, strlen(TAGMAGIC));
    free(op.packet);
    if (!*vendor)
        return OGGEDIT_CANNOT_PARSE_HEADERS;

#ifdef HAVE_OGG_STREAM_FLUSH_FILL
    if (op.bytes < MAXPAYLOAD * (pages-1))
        return 4; // prevent in-place write if the packet is weirdly split into too many pages
#else
    return 4; // not safe to pad without ogg_stream_flush_fill
#endif

    return op.bytes;
}
Esempio n. 2
0
static ptrdiff_t check_vorbis_headers(DB_FILE *in, ogg_sync_state *oy, const off_t offset, char **vendor, ogg_packet *codebooks)
{
    ogg_stream_state os;
    ogg_page og;
    const int64_t serial = init_read_stream(in, oy, &os, &og, offset, VORBISNAME);
    if (serial <= OGGEDIT_EOF)
        return serial;

    ogg_packet vc;
    int pages = read_packet(in, oy, &os, &og, &vc, 1);
    if (pages > OGGEDIT_EOF)
        pages = read_packet(in, oy, &os, &og, codebooks, pages);
    ogg_stream_clear(&os);
    if (pages <= OGGEDIT_EOF)
        return pages;

    if (vc.bytes > strlen(VCMAGIC) && !memcmp(vc.packet, VCMAGIC, strlen(VCMAGIC)) &&
        codebooks->bytes > strlen(CODEMAGIC) && !memcmp(codebooks->packet, CODEMAGIC, strlen(CODEMAGIC)))
        *vendor = parse_vendor(&vc, strlen(VCMAGIC));
    free(vc.packet);
    if (!*vendor)
        return OGGEDIT_CANNOT_PARSE_HEADERS;

#ifdef HAVE_OGG_STREAM_FLUSH_FILL
    if ((vc.bytes + codebooks->bytes) < MAXPAYLOAD * (pages-1))
        return 4; // prevent in-place write if the packets are split over too many pages
#else
    return 4; // not safe to pad without ogg_stream_flush_fill
#endif

    return vc.bytes;
}
Esempio n. 3
0
static int
parse_db(FILE *f, pcidb_hdl_t *hdl)
{
	char buf[1024];
	pcidb_vendor_t *v = NULL;
	pcidb_device_t *d = NULL;
	pcidb_parse_t state = PDB_VENDOR;

	for (;;) {
		errno = 0;
		if (readline(f, buf, sizeof (buf)) != 0) {
			if (errno != 0)
				return (-1);
			else
				return (0);
		}

newstate:
		switch (state) {
		case PDB_VENDOR:
			v = parse_vendor(buf, hdl);
			if (v == NULL)
				return (NULL);
			state = PDB_DEVICE;
			continue;
		case PDB_DEVICE:
			if (buf[0] != '\t') {
				state = PDB_VENDOR;
				goto newstate;
			}

			if (buf[1] == '\t') {
				state = PDB_SUBDEV;
				goto newstate;
			}

			assert(v != NULL);
			d = parse_device(buf, v);
			if (d == NULL)
				return (NULL);
			continue;
		case PDB_SUBDEV:
			if (buf[0] != '\t') {
				state = PDB_VENDOR;
				goto newstate;
			}

			if (buf[0] == '\t' && buf[1] != '\t') {
				state = PDB_DEVICE;
				goto newstate;
			}

			assert(buf[0] == '\t' && buf[1] == '\t');
			assert(d != NULL);
			(void) parse_subdev(buf, d);
		}
	}
}