Commit e46fe21f authored by Mans Rullgard's avatar Mans Rullgard

limit sync search length

parent 5273fd79
......@@ -123,12 +123,15 @@ int64_t get_sbits(struct bitreader *b, int n)
return v << s >> s;
}
int find_sync(struct bitreader *b, uint64_t magic, int len)
int find_sync(struct bitreader *b, uint64_t magic, int len, int max)
{
while (peek_bits64(b, len, 0) != magic)
while (max--) {
if (peek_bits64(b, len, 0) == magic)
return 0;
get_ubits(b, 1);
}
return 0;
return -1;
}
void init_bits(struct bitreader *b)
......
......@@ -40,7 +40,7 @@ struct bitreader {
};
void init_bits(struct bitreader *b);
int find_sync(struct bitreader *b, uint64_t magic, int len);
int find_sync(struct bitreader *b, uint64_t magic, int len, int max);
uint64_t get_ubits(struct bitreader *b, int n);
int64_t get_sbits(struct bitreader *b, int n);
uint32_t peek_bits(struct bitreader *b, unsigned n, unsigned offs);
......
......@@ -249,7 +249,10 @@ static const struct frame packets[16] = {
static int find_mqa_sync(struct bitreader *b)
{
find_sync(b, MQA_MAGIC, 40);
int err = find_sync(b, MQA_MAGIC, 40, 65536);
if (err)
return err;
if (peek_bits(b, 1, 40)) {
int n = peek_bits(b, 7, 73);
......@@ -356,8 +359,8 @@ static int scan_file(const char *name, int start, int mqabit)
br.msb = 0;
br.get_bits_cb = get_bits_cb;
br.eof_cb = eof_cb;
find_mqa_sync(&br);
scan_mqa(&br);
if (!find_mqa_sync(&br))
scan_mqa(&br);
}
print_end();
......
......@@ -192,7 +192,7 @@ int main(int argc, char **argv)
init_bits(&fb);
fb.fill_bits = fill_bits_mqb;
find_sync(&br, MQB_MARKER, 56);
find_sync(&br, MQB_MARKER, 56, 1024);
for (;;)
print_mqb_frame(&fb);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment