diff --git a/ChangeLog b/ChangeLog index 315c4f4e..9e28a07e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-10-19 Tatsuhiro Tsujikawa + + Fixed the bug that aria2 aborts when a request larger than 16KiB is + recieved. + In this fix, if a request larger than 16KiB length is received, aria2 + disconnects the peer. + * src/BtConstants.h + * src/PeerMessageUtil.cc + * src/PeerMessageUtil.h + * test/BtRequestMessageTest.cc + 2008-10-14 Tatsuhiro Tsujikawa * Release 0.16.1 diff --git a/src/BtConstants.h b/src/BtConstants.h index 52c90c23..3d1b9cf9 100644 --- a/src/BtConstants.h +++ b/src/BtConstants.h @@ -47,4 +47,6 @@ typedef std::map Extensions; #define DEFAULT_LATENCY 1500 +#define MAX_BLOCK_LENGTH (16*1024) + #endif // _D_BT_CONSTANTS_ diff --git a/src/PeerMessageUtil.cc b/src/PeerMessageUtil.cc index 911af937..209ee00e 100644 --- a/src/PeerMessageUtil.cc +++ b/src/PeerMessageUtil.cc @@ -33,11 +33,14 @@ */ /* copyright --> */ #include "PeerMessageUtil.h" + +#include +#include + #include "DlAbortEx.h" #include "a2netcompat.h" #include "StringFormat.h" -#include -#include +#include "BtConstants.h" namespace aria2 { diff --git a/src/PeerMessageUtil.h b/src/PeerMessageUtil.h index d0121425..b3de793c 100644 --- a/src/PeerMessageUtil.h +++ b/src/PeerMessageUtil.h @@ -41,8 +41,6 @@ namespace aria2 { -#define MAX_BLOCK_LENGTH (128*1024) - class PeerMessageUtil { private: PeerMessageUtil() {} diff --git a/test/BtRequestMessageTest.cc b/test/BtRequestMessageTest.cc index 99d4d85c..c6d990cb 100644 --- a/test/BtRequestMessageTest.cc +++ b/test/BtRequestMessageTest.cc @@ -1,4 +1,9 @@ #include "BtRequestMessage.h" + +#include + +#include + #include "PeerMessageUtil.h" #include "MockBtContext.h" #include "MockBtMessage.h" @@ -16,8 +21,7 @@ #include "ExtensionMessageFactory.h" #include "FileEntry.h" #include "BtHandshakeMessage.h" -#include -#include +#include "BtRequestMessageValidator.h" namespace aria2 { @@ -36,6 +40,8 @@ class BtRequestMessageTest:public CppUnit::TestFixture { CPPUNIT_TEST(testHandleAbortRequestEvent_alreadyInvalidated); CPPUNIT_TEST(testHandleAbortRequestEvent_sendingInProgress); CPPUNIT_TEST(testToString); + CPPUNIT_TEST(testValidate); + CPPUNIT_TEST(testValidate_lengthTooLong); CPPUNIT_TEST_SUITE_END(); private: @@ -52,6 +58,8 @@ public: void testHandleAbortRequestEvent_alreadyInvalidated(); void testHandleAbortRequestEvent_sendingInProgress(); void testToString(); + void testValidate(); + void testValidate_lengthTooLong(); class MockPieceStorage2 : public MockPieceStorage { public: @@ -283,4 +291,29 @@ void BtRequestMessageTest::testToString() { msg->toString()); } +void BtRequestMessageTest::testValidate() { + BtRequestMessage msg(0, 0, 16*1024); + msg.setBtMessageValidator + (SharedHandle + (new BtRequestMessageValidator(&msg, 1024, 256*1024))); + std::deque errors; + + msg.validate(errors); +} + +void BtRequestMessageTest::testValidate_lengthTooLong() { + BtRequestMessage msg(0, 0, 16*1024+1); + msg.setBtMessageValidator + (SharedHandle + (new BtRequestMessageValidator(&msg, 1024, 256*1024))); + std::deque errors; + try { + msg.validate(errors); + CPPUNIT_FAIL("exception must be thrown."); + } catch(DlAbortEx& e) { + CPPUNIT_ASSERT_EQUAL(std::string("Length too long: 16385 > 16KB"), + std::string(e.what())); + } +} + } // namespace aria2