diff --git a/src/http_parser.cpp b/src/http_parser.cpp index dcf4e185b..70589b614 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -370,8 +370,6 @@ restart_response: if (chunk_size == 0) { m_finished = true; - TORRENT_ASSERT(m_content_length < 0 || m_recv_pos - m_body_start_pos - - m_chunk_header_size == m_content_length); } header_size -= m_partial_chunk_header; m_partial_chunk_header = 0; diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 4ff9ae15f..d695a9a6c 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -407,6 +407,11 @@ namespace { filename = p.string_ptr() + info_ptr_diff; filename_len = p.string_length(); sanitize_append_path_element(path, p.string_value()); + if (path.empty()) + { + ec = errors::torrent_missing_name; + return false; + } } else { diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index 109b8cd2e..ce429d619 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -657,3 +657,26 @@ TORRENT_TEST(invalid_chunk_2) feed_bytes(parser, {reinterpret_cast(invalid_chunked_input), sizeof(invalid_chunked_input)}); } +TORRENT_TEST(invalid_chunk_3) +{ + std::uint8_t const invalid_chunked_input[] = { + 0x48, 0xff, 0xff, 0xff, 0xfd, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x32, 0x30, 0x30, // H....TTP/1.1 200 + 0x20, 0x4f, 0x4b, 0x0a, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x2d, 0x45, 0x6e, 0x63, // OK.Transfer-Enc + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x65, 0x64, 0x0a, 0x44, // oding: chunked.D + 0x61, 0x74, 0x65, 0x3a, 0x20, 0x53, 0x61, 0x74, 0x2c, 0x20, 0x33, 0x31, 0x20, 0x41, 0x75, 0x67, // ate: Sat, 0x31, Aug + 0x20, 0x32, 0x30, 0x30, 0x32, 0x20, 0x30, 0x30, 0x3a, 0x32, 0x34, 0x3a, 0x30, 0x38, 0x20, 0x47, // 2002 0x00,:0x24,:0x08, G + 0x4d, 0x54, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x63, // MT.Connection: c + 0x6c, 0x6f, 0x73, 0x65, 0x0a, 0x0a, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, // lose..0000000000 + 0x36, 0x34, 0x0a, 0x6c, 0x72, 0x79, 0x6d, 0x68, 0x74, 0x67, 0x6b, 0x7a, 0x71, 0x74, 0x71, 0x71, // 0x64,.lrymhtgkzqtqq + 0x62, 0x75, 0x71, 0x69, 0x66, 0x76, 0x69, 0x74, 0x6b, 0x70, 0x69, 0x63, 0x6f, 0x64, 0x67, 0x77, // buqifvitkpicodgw + 0x6d, 0x69, 0x6a, 0x64, 0x67, 0x76, 0x6b, 0x63, 0x65, 0x78, 0x64, 0x75, 0x71, 0x74, 0x6e, 0x74, // mijdgvkcexduqtnt + 0x6e, 0x66, 0x62, 0x75, 0x64, 0x6d, 0x6e, 0x6e, 0x62, 0x78, 0x72, 0x72, 0x63, 0x78, 0x6e, 0x70, // nfbudmnnbxrrcxnp + 0x66, 0x79, 0x73, 0x6f, 0x74, 0x66, 0x71, 0x7a, 0x63, 0x74, 0x77, 0x75, 0x6d, 0x6a, 0x6e, 0x63, // fysotfqzctwumjnc + 0x6f, 0x71, 0x77, 0x72, 0x63, 0x6d, 0x67, 0x64, 0x6c, 0x78, 0x77, 0x6f, 0x78, 0x6c, 0x64, 0x65, // oqwrcmgdlxwoxlde + 0x6a, 0x76, 0x73, 0x66, 0x63, 0x6b, 0x65, 0x0a, 0x30, 0x0a, 0x0a, 0x0a, // jvsfcke.0... + }; + + http_parser parser; + feed_bytes(parser, {reinterpret_cast(invalid_chunked_input), sizeof(invalid_chunked_input)}); +} + diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 6afbed57e..9e2d861f4 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -140,6 +140,7 @@ test_failing_torrent_t test_error_torrents[] = { "invalid_piece_len.torrent", errors::torrent_missing_piece_length }, { "negative_piece_len.torrent", errors::torrent_missing_piece_length }, { "no_name.torrent", errors::torrent_missing_name }, + { "bad_name.torrent", errors::torrent_missing_name }, { "invalid_name.torrent", errors::torrent_missing_name }, { "invalid_info.torrent", errors::torrent_missing_info }, { "string.torrent", errors::torrent_is_no_dict }, diff --git a/test/test_torrents/bad_name.torrent b/test/test_torrents/bad_name.torrent new file mode 100644 index 000000000..2dbaf91f8 Binary files /dev/null and b/test/test_torrents/bad_name.torrent differ