Skip to content

Commit e82b6ee

Browse files
authored
Fix crash occured by .m3u8 file saved for Playlist (#39333)
When a saved .m3u8 points some other relative url, PlaylistDataSource might be requested to serve unknown url. For example, in a media.m3u8 ``` /amplify_video/2091454598288449536/pl/avc1/480x270/ESjKu9eJEx6jexZe.m3u8 ``` The relative url on the second line is resolvd to "chrome-untrusted://playlist-data/amplyfy_video..." inheriting origin from the source url. So instead of crashing the browser, fallback to unknown type.
1 parent de5a44b commit e82b6ee

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

browser/playlist/playlist_data_source.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ PlaylistDataSource::DataRequest::DataRequest(const GURL& url) {
149149
const auto full_path = content::URLDataSource::URLToRequestPath(url);
150150
const auto paths = base::SplitStringPiece(
151151
full_path, "/", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
152-
CHECK_EQ(paths.size(), 2u) << url.spec();
152+
if (paths.size() != 2) {
153+
LOG(ERROR) << "Invalid playlist data source URL, might be routed from "
154+
"saved .m3u8 file: "
155+
<< url.spec();
156+
return;
157+
}
153158

154159
id = paths.at(0);
155160
const auto& type_string = paths.at(1);
@@ -160,7 +165,10 @@ PlaylistDataSource::DataRequest::DataRequest(const GURL& url) {
160165
} else if (type_string == "favicon") {
161166
type = DataRequest::Type::kFavicon;
162167
} else {
163-
NOTREACHED() << "type is not in {thumbnail,media,favicon}: " << type_string;
168+
type = DataRequest::Type::kNone;
169+
LOG(ERROR) << "Invalid playlist data source URL, might be routed from "
170+
"saved .m3u8 file: "
171+
<< url.spec();
164172
}
165173
}
166174

@@ -187,6 +195,9 @@ void PlaylistDataSource::StartDataRequest(
187195
}
188196

189197
switch (DataRequest data_request(url); data_request.type) {
198+
case DataRequest::Type::kNone:
199+
std::move(got_data_callback).Run(nullptr);
200+
break;
190201
case DataRequest::Type::kThumbnail:
191202
GetThumbnail(data_request, wc_getter, std::move(got_data_callback));
192203
break;
@@ -204,8 +215,10 @@ void PlaylistDataSource::StartRangeDataRequest(
204215
const net::HttpByteRange& range,
205216
GotRangeDataCallback callback) {
206217
DataRequest data_request(url);
207-
CHECK_EQ(data_request.type, DataRequest::Type::kMedia);
208-
CHECK(range.IsValid());
218+
if (data_request.type != DataRequest::Type::kMedia || !range.IsValid()) {
219+
std::move(callback).Run({});
220+
return;
221+
}
209222
GetMediaFile(data_request, wc_getter, range, std::move(callback));
210223
}
211224

@@ -281,6 +294,8 @@ std::string PlaylistDataSource::GetMimeType(const GURL& url) {
281294
// actual file extension in WebUIUrlLoader.
282295
case DataRequest::Type::kFavicon:
283296
return FaviconSource::GetMimeType(url);
297+
case DataRequest::Type::kNone:
298+
return {};
284299
}
285300
}
286301

browser/playlist/playlist_data_source.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PlaylistDataSource : public FaviconSource {
4343
private:
4444
struct DataRequest {
4545
enum class Type {
46+
kNone,
4647
kThumbnail,
4748
kMedia,
4849
kFavicon,
@@ -54,7 +55,7 @@ class PlaylistDataSource : public FaviconSource {
5455
~DataRequest();
5556

5657
std::string id;
57-
Type type;
58+
Type type = Type::kNone;
5859
};
5960

6061
void GetThumbnail(const DataRequest& request,

0 commit comments

Comments
 (0)