From f363817f143a7cee0ccdb7833a99ac1e8f210197 Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Sat, 27 May 2017 18:25:31 -0600 Subject: [PATCH] net/http: fix application/ogg sniff signature I accidentally set the wrong pattern mask as * []byte("\x4F\x67\x67\x53\x00") --> "OggS", the byte pattern itself. instead of * []byte("\xFF\xFF\xFF\xFF\xFF") which was a copy-paste error. The correct pattern is described at https://mimesniff.spec.whatwg.org/#matching-an-audio-or-video-type-pattern which I was using as a reference but I mistyped. Fixes #20513 Change-Id: Ie9cb60ac7edbf03075070878775b964116ce92d0 Reviewed-on: https://go-review.googlesource.com/44336 Run-TryBot: Emmanuel Odeke Reviewed-by: Joe Tsai --- src/net/http/sniff.go | 4 ++-- src/net/http/sniff_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/net/http/sniff.go b/src/net/http/sniff.go index 0d21b44a56..ecc65e4de6 100644 --- a/src/net/http/sniff.go +++ b/src/net/http/sniff.go @@ -107,8 +107,8 @@ var sniffSignatures = []sniffSig{ ct: "audio/basic", }, &maskedSig{ - mask: []byte("OggS\x00"), - pat: []byte("\x4F\x67\x67\x53\x00"), + mask: []byte("\xFF\xFF\xFF\xFF\xFF"), + pat: []byte("OggS\x00"), ct: "application/ogg", }, &maskedSig{ diff --git a/src/net/http/sniff_test.go b/src/net/http/sniff_test.go index 38f3f8197e..24f1298e5d 100644 --- a/src/net/http/sniff_test.go +++ b/src/net/http/sniff_test.go @@ -45,7 +45,11 @@ var sniffTests = []struct { {"WAV audio #1", []byte("RIFFb\xb8\x00\x00WAVEfmt \x12\x00\x00\x00\x06"), "audio/wave"}, {"WAV audio #2", []byte("RIFF,\x00\x00\x00WAVEfmt \x12\x00\x00\x00\x06"), "audio/wave"}, {"AIFF audio #1", []byte("FORM\x00\x00\x00\x00AIFFCOMM\x00\x00\x00\x12\x00\x01\x00\x00\x57\x55\x00\x10\x40\x0d\xf3\x34"), "audio/aiff"}, + {"OGG audio", []byte("OggS\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x7e\x46\x00\x00\x00\x00\x00\x00\x1f\xf6\xb4\xfc\x01\x1e\x01\x76\x6f\x72"), "application/ogg"}, + {"Must not match OGG", []byte("owow\x00"), "application/octet-stream"}, + {"Must not match OGG", []byte("oooS\x00"), "application/octet-stream"}, + {"Must not match OGG", []byte("oggS\x00"), "application/octet-stream"}, // Video types. {"MP4 video", []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom<\x06t\xbfmdat"), "video/mp4"},