]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flac_parser.c
avcodec/flac_parser: Use native endianness when possible
[ffmpeg] / libavcodec / flac_parser.c
index 84da23f327e1f3bb80de6d945d7676085ae5d6aa..5d0705ce631f7563ec5a305aa99a6594be2495e3 100644 (file)
@@ -221,7 +221,7 @@ static int find_headers_search(FLACParseContext *fpc, uint8_t *buf, int buf_size
     }
 
     for (; i < buf_size - 1; i += 4) {
-        x = AV_RB32(buf + i);
+        x = AV_RN32(buf + i);
         if (((x & ~(x + 0x01010101)) & 0x80808080)) {
             for (j = 0; j < 4; j++) {
                 if ((AV_RB16(buf + i + j) & 0xFFFE) == 0xFFF8)
@@ -686,12 +686,17 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
     }
 
     for (curr = fpc->headers; curr; curr = curr->next) {
-        if (curr->max_score > 0 &&
-            (!fpc->best_header || curr->max_score > fpc->best_header->max_score)) {
+        if (!fpc->best_header || curr->max_score > fpc->best_header->max_score) {
             fpc->best_header = curr;
         }
     }
 
+    if (fpc->best_header && fpc->best_header->max_score <= 0) {
+        // Only accept a bad header if there is no other option to continue
+        if (!buf_size || !buf || read_end != buf || fpc->nb_headers_buffered < FLAC_MIN_HEADERS)
+            fpc->best_header = NULL;
+    }
+
     if (fpc->best_header) {
         fpc->best_header_valid = 1;
         if (fpc->best_header->offset > 0) {