[nginx-tests] Tests: moved bad mp4 test to a separate file.
Maxim Dounin
mdounin at mdounin.ru
Tue Mar 10 01:41:14 UTC 2026
details: http://freenginx.org/hg/nginx-tests/rev/d6429eb46e37
branches:
changeset: 2042:d6429eb46e37
user: Maxim Dounin <mdounin at mdounin.ru>
date: Tue Mar 10 04:32:36 2026 +0300
description:
Tests: moved bad mp4 test to a separate file.
diffstat:
mp4.t | 35 +------------------
mp4_bad.t | 116 ++++++++++++++-----------------------------------------------
2 files changed, 28 insertions(+), 123 deletions(-)
diffs (217 lines):
diff --git a/mp4.t b/mp4.t
--- a/mp4.t
+++ b/mp4.t
@@ -65,23 +65,7 @@ system('ffmpeg -nostdin -loglevel quiet
. "${\($t->testdir())}/no_mdat.mp4") == 0
or die "Can't create mp4 file: $!";
-my $sbad = <<'EOF';
-00000000: 00 00 00 1c 66 74 79 70 69 73 6f 6d 00 00 02 00 |....ftypisom....|
-00000010: 69 73 6f 6d 69 73 6f 32 6d 70 34 31 00 00 00 09 |isomiso2mp41....|
-00000020: 6d 64 61 74 00 00 00 00 94 6d 6f 6f 76 00 00 00 |mdat.....moov...|
-00000030: 8c 74 72 61 6b 00 00 00 84 6d 64 69 61 00 00 00 |.trak....mdia...|
-00000040: 7c 6d 69 6e 66 00 00 00 74 73 74 62 6c 00 00 00 ||minf...tstbl...|
-00000050: 18 73 74 74 73 00 00 00 00 00 00 00 01 00 00 03 |.stts...........|
-00000060: 3a 00 00 04 00 00 00 00 28 73 74 73 63 00 00 00 |:.......(stsc...|
-00000070: 00 00 00 00 02 00 00 00 01 00 00 03 0f 00 00 00 |................|
-00000080: 01 00 00 00 02 00 00 00 2b 00 00 00 01 00 00 00 |........+.......|
-00000090: 14 73 74 73 7a 00 00 00 00 00 00 05 a9 00 00 03 |.stsz...........|
-000000a0: 3b 00 00 00 18 63 6f 36 34 00 00 00 00 00 00 00 |;....co64.......|
-000000b0: 01 ff ff ff ff f0 0f fb e7 |.........|
-EOF
-
-$t->write_file('bad.mp4', unhex($sbad));
-$t->run()->plan(27);
+$t->run()->plan(26);
###############################################################################
@@ -115,10 +99,6 @@ like(http_head("$test_uri?start=21"), qr
$test_uri = '/no_mdat.mp4', goto again unless $test_uri eq '/no_mdat.mp4';
-# corrupted formats
-
-like(http_get("/bad.mp4?start=0.5"), qr/500 Internal/, 'co64 chunk beyond EOF');
-
###############################################################################
sub durations {
@@ -143,17 +123,4 @@ sub durations {
sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g;
}
-sub unhex {
- my ($input) = @_;
- my $buffer = '';
-
- for my $l ($input =~ m/: +((?:[0-9a-f]{2,4} +)+) /gms) {
- for my $v ($l =~ m/[0-9a-f]{2}/g) {
- $buffer .= chr(hex($v));
- }
- }
-
- return $buffer;
-}
-
###############################################################################
diff --git a/mp4.t b/mp4_bad.t
copy from mp4.t
copy to mp4_bad.t
--- a/mp4.t
+++ b/mp4_bad.t
@@ -1,10 +1,10 @@
#!/usr/bin/perl
+# (C) Maxim Dounin
# (C) Sergey Kandaurov
# (C) Nginx, Inc.
-# Tests for mp4 module.
-# Ensures that requested stream duration is given with sane accuracy.
+# Tests for mp4 module, various bad mp4 files.
###############################################################################
@@ -16,15 +16,14 @@ use Test::More;
BEGIN { use FindBin; chdir($FindBin::Bin); }
use lib 'lib';
-use Test::Nginx qw/ :DEFAULT http_content /;
+use Test::Nginx;
###############################################################################
select STDERR; $| = 1;
select STDOUT; $| = 1;
-my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffprobe')
- ->has_daemon('ffmpeg')
+my $t = Test::Nginx->new()->has(qw/http mp4/)->plan(1)
->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
@@ -49,100 +48,39 @@ http {
EOF
-plan(skip_all => 'no lavfi')
- unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`;
-system('ffmpeg -nostdin -loglevel quiet -y '
- . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 '
- . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 '
- . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v mpeg4 '
- . "${\($t->testdir())}/test.mp4") == 0
- or die "Can't create mp4 file: $!";
-system('ffmpeg -nostdin -loglevel quiet -y '
- . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 '
- . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 '
- . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v mpeg4 '
- . '-movflags +faststart '
- . "${\($t->testdir())}/no_mdat.mp4") == 0
- or die "Can't create mp4 file: $!";
+# chunk offset in stco/co64 atom beyond the end of file
-my $sbad = <<'EOF';
+my $bad_co64 = <<'EOF';
00000000: 00 00 00 1c 66 74 79 70 69 73 6f 6d 00 00 02 00 |....ftypisom....|
-00000010: 69 73 6f 6d 69 73 6f 32 6d 70 34 31 00 00 00 09 |isomiso2mp41....|
-00000020: 6d 64 61 74 00 00 00 00 94 6d 6f 6f 76 00 00 00 |mdat.....moov...|
-00000030: 8c 74 72 61 6b 00 00 00 84 6d 64 69 61 00 00 00 |.trak....mdia...|
-00000040: 7c 6d 69 6e 66 00 00 00 74 73 74 62 6c 00 00 00 ||minf...tstbl...|
-00000050: 18 73 74 74 73 00 00 00 00 00 00 00 01 00 00 03 |.stts...........|
-00000060: 3a 00 00 04 00 00 00 00 28 73 74 73 63 00 00 00 |:.......(stsc...|
-00000070: 00 00 00 00 02 00 00 00 01 00 00 03 0f 00 00 00 |................|
-00000080: 01 00 00 00 02 00 00 00 2b 00 00 00 01 00 00 00 |........+.......|
-00000090: 14 73 74 73 7a 00 00 00 00 00 00 05 a9 00 00 03 |.stsz...........|
-000000a0: 3b 00 00 00 18 63 6f 36 34 00 00 00 00 00 00 00 |;....co64.......|
-000000b0: 01 ff ff ff ff f0 0f fb e7 |.........|
+00000000: 69 73 6f 6d 69 73 6f 32 6d 70 34 31 |isomiso2mp41|
+00000000: 00 00 00 08 6d 64 61 74 |....mdat|
+00000000: 00 00 00 94 6d 6f 6f 76 |....moov|
+00000000: 00 00 00 8c 74 72 61 6b |....trak|
+00000000: 00 00 00 84 6d 64 69 61 |....mdia|
+00000000: 00 00 00 7c 6d 69 6e 66 |....minf|
+00000000: 00 00 00 74 73 74 62 6c |....stbl|
+00000000: 00 00 00 18 73 74 74 73 00 00 00 00 00 00 00 01 |....stts........|
+00000000: 00 00 03 3a 00 00 04 00 |........|
+00000000: 00 00 00 28 73 74 73 63 00 00 00 00 00 00 00 01 |....stsc........|
+00000000: 00 00 00 01 ff ff ff ff 00 00 00 00 |............|
+00000000: 00 00 00 02 ff ff ff ff 00 00 00 00 |............|
+00000000: 00 00 00 14 73 74 73 7a 00 00 00 00 00 00 05 a9 |....stsz........|
+00000000: 00 00 03 3b |....|
+00000000: 00 00 00 18 63 6f 36 34 00 00 00 00 00 00 00 01 |....co64........|
+00000000: ff ff ff ff f0 0f fb e7 |........|
EOF
-$t->write_file('bad.mp4', unhex($sbad));
-$t->run()->plan(27);
+$t->write_file('bad_co64.mp4', unhex($bad_co64));
+
+$t->run();
###############################################################################
-my $test_uri = '/test.mp4';
-
-again:
-
-is(durations($t, 0.0), '10.0 20.0', 'start zero');
-is(durations($t, 2), '8.0 18.0', 'start integer');
-is(durations($t, 7.1), '2.9 12.9', 'start float');
-
-is(durations($t, 6, 9), '3.0 3.0', 'start end integer');
-is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float');
-
-is(durations($t, undef, 9), '9.0 9.0', 'end integer');
-is(durations($t, undef, 5.6), '5.6 5.6', 'end float');
-
-# invalid range results in ignoring end argument
-
-like(http_head("$test_uri?start=1&end=1"), qr/200 OK/, 'zero range');
-like(http_head("$test_uri?start=1&end=0"), qr/200 OK/, 'negative range');
-
-# start/end values exceeding track/file duration
-
-unlike(http_head("$test_uri?end=11"), qr!HTTP/1.1 500!,
- 'end beyond short track');
-unlike(http_head("$test_uri?end=21"), qr!HTTP/1.1 500!, 'end beyond EOF');
-unlike(http_head("$test_uri?start=11"), qr!HTTP/1.1 500!,
- 'start beyond short track');
-like(http_head("$test_uri?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF');
-
-$test_uri = '/no_mdat.mp4', goto again unless $test_uri eq '/no_mdat.mp4';
-
-# corrupted formats
-
-like(http_get("/bad.mp4?start=0.5"), qr/500 Internal/, 'co64 chunk beyond EOF');
+like(http_get("/bad_co64.mp4?start=0.5"), qr/500 Internal/,
+ 'co64 chunk after eof');
###############################################################################
-sub durations {
- my ($t, $start, $end) = @_;
- my $path = $t->{_testdir} . '/frag.mp4';
-
- my $uri = $test_uri;
- if (defined $start) {
- $uri .= "?start=$start";
- if (defined $end) {
- $uri .= "&end=$end";
- }
-
- } elsif (defined $end) {
- $uri .= "?end=$end";
- }
-
- $t->write_file('frag.mp4', http_content(http_get($uri)));
-
- my $r = `ffprobe -show_streams $path 2>/dev/null`;
- Test::Nginx::log_core('||', $r);
- sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g;
-}
-
sub unhex {
my ($input) = @_;
my $buffer = '';
More information about the nginx-devel
mailing list