From 6edfa4e430d4f44dbcbb26dd236028bcc503a312 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 10 Aug 2011 23:58:49 +0900 Subject: Limit maximum length of ByteArrayWriter. aria2 downloads meta files such as .torrent and .metalink file in memory using ByteArrayWriter. To prevent accidentally download big file, we set the maximum length that ByteArrayWriter can hold. The default is 5MiB and it is reasonable because most .torrent and .metalink file are much smaller than that. --- src/ByteArrayDiskWriter.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/ByteArrayDiskWriter.cc') diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc index 51974003..bb81dcd1 100644 --- a/src/ByteArrayDiskWriter.cc +++ b/src/ByteArrayDiskWriter.cc @@ -34,10 +34,14 @@ /* copyright --> */ #include "ByteArrayDiskWriter.h" #include "A2STR.h" +#include "DlAbortEx.h" +#include "fmt.h" namespace aria2 { -ByteArrayDiskWriter::ByteArrayDiskWriter() {} +ByteArrayDiskWriter::ByteArrayDiskWriter(size_t maxLength) + : maxLength_(maxLength) +{} ByteArrayDiskWriter::~ByteArrayDiskWriter() {} @@ -62,6 +66,10 @@ void ByteArrayDiskWriter::openExistingFile(uint64_t totalLength) void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position) { + if(position+dataLength > maxLength_) { + throw DL_ABORT_EX(fmt("Maximum length(%lu) exceeded.", + static_cast(maxLength_))); + } uint64_t length = size(); if(length < (uint64_t)position) { buf_.seekp(length, std::ios::beg); -- cgit