Skip to content

Commit a7473d3

Browse files
authored
Merge pull request #2182 from nextcloud/fix/break-mp3-parse-on-invalid-frame
fix: mp3info break frame parsing on short frames
2 parents ad371b5 + 57cd0c1 commit a7473d3

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 186b99ac4a57d091e9414c0944524a9e098835f3 Mon Sep 17 00:00:00 2001
2+
From: grnd-alt <[email protected]>
3+
Date: Mon, 13 Oct 2025 12:18:37 +0200
4+
Subject: [PATCH] fix: break frame parsing on short frame
5+
6+
Signed-off-by: grnd-alt <[email protected]>
7+
---
8+
src/Mp3Info.php | 5 +++++
9+
1 file changed, 5 insertions(+)
10+
11+
diff --git a/src/Mp3Info.php b/src/Mp3Info.php
12+
index ccf97f4..24781d7 100644
13+
--- a/src/Mp3Info.php
14+
+++ b/src/Mp3Info.php
15+
@@ -584,6 +584,11 @@ protected function parseId3v23Body($fp, $lastByte) {
16+
$raw = fread($fp, 10);
17+
$frame_id = substr($raw, 0, 4);
18+
19+
+ if (strlen($raw) < 10) {
20+
+ fseek($fp, $lastByte);
21+
+ break;
22+
+ }
23+
+
24+
if ($frame_id == str_repeat(chr(0), 4)) {
25+
fseek($fp, $lastByte);
26+
break;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 37365fd60dd3f4a637a887376b32f4d5e05726ce Mon Sep 17 00:00:00 2001
2+
From: wapmorgan <[email protected]>
3+
Date: Sat, 28 Jun 2025 03:34:24 +0300
4+
Subject: [PATCH] #30 Fix incorrect lookup for mpeg header. Previously it skips
5+
1 extra byte every jump that leads to 50/50% chance to find mpeg header
6+
7+
---
8+
bin/mp3scan | 2 +-
9+
src/Mp3Info.php | 1 -
10+
2 files changed, 1 insertion(+), 2 deletions(-)
11+
12+
diff --git a/bin/mp3scan b/bin/mp3scan
13+
index 8f3e28c..6352cc5 100755
14+
--- a/bin/mp3scan
15+
+++ b/bin/mp3scan
16+
@@ -1,4 +1,4 @@
17+
-#!/usr/bin/php
18+
+#!/usr/bin/env php
19+
<?php
20+
use wapmorgan\Mp3Info\Mp3Info;
21+
22+
diff --git a/src/Mp3Info.php b/src/Mp3Info.php
23+
index 17e4074..ccf97f4 100644
24+
--- a/src/Mp3Info.php
25+
+++ b/src/Mp3Info.php
26+
@@ -363,7 +363,6 @@ private function readMpegFrame($fp) {
27+
break;
28+
}
29+
}
30+
- fseek($fp, 1, SEEK_CUR);
31+
} while (ftell($fp) <= $header_seek_pos);
32+
33+
if (!isset($header_bytes) || $header_bytes[0] !== 0xFF || (($header_bytes[1] >> 5) & 0b111) != 0b111) {

composer.patches.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"patches": {}
2+
"patches": {
3+
"wapmorgan/mp3info": {
4+
"Break frame parsing on invalid frame": ".patches/mp3info-break-frame-parsing.patch",
5+
"fix incorrect lookup for mpeg header": ".patches/mp3info-fix-incorrect-lookup-for-mpeg-header.patch"
6+
}
7+
}
38
}

composer/installed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6183,6 +6183,12 @@
61836183
"bin/mp3scan"
61846184
],
61856185
"type": "library",
6186+
"extra": {
6187+
"patches_applied": {
6188+
"Break frame parsing on invalid frame": ".patches/mp3info-break-frame-parsing.patch",
6189+
"fix incorrect lookup for mpeg header": ".patches/mp3info-fix-incorrect-lookup-for-mpeg-header.patch"
6190+
}
6191+
},
61866192
"installation-source": "dist",
61876193
"autoload": {
61886194
"psr-4": {

wapmorgan/mp3info/PATCHES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches)
2+
Patches applied to this directory:
3+
4+
Break frame parsing on invalid frame
5+
Source: .patches/mp3info-break-frame-parsing.patch
6+
7+
8+
fix incorrect lookup for mpeg header
9+
Source: .patches/mp3info-fix-incorrect-lookup-for-mpeg-header.patch
10+
11+

wapmorgan/mp3info/src/Mp3Info.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ private function readMpegFrame($fp) {
363363
break;
364364
}
365365
}
366-
fseek($fp, 1, SEEK_CUR);
367366
} while (ftell($fp) <= $header_seek_pos);
368367

369368
if (!isset($header_bytes) || $header_bytes[0] !== 0xFF || (($header_bytes[1] >> 5) & 0b111) != 0b111) {
@@ -585,6 +584,11 @@ protected function parseId3v23Body($fp, $lastByte) {
585584
$raw = fread($fp, 10);
586585
$frame_id = substr($raw, 0, 4);
587586

587+
if (strlen($raw) < 10) {
588+
fseek($fp, $lastByte);
589+
break;
590+
}
591+
588592
if ($frame_id == str_repeat(chr(0), 4)) {
589593
fseek($fp, $lastByte);
590594
break;

0 commit comments

Comments
 (0)