From f7305de3020727b1e9bf6e5bc2321a668ab9845e Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 17 May 2010 21:05:28 +0000 Subject: [PATCH] added a workaround for a bug in the cache system that asks for files of size 2^64-1. This results into a division by zero in ftChunkMap. Bu the time I find this bug, the workaroudn should avoid crashes. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2932 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftcontroller.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index a26244210..d11da5923 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -1002,6 +1002,20 @@ bool ftController::FileRequest(std::string fname, std::string hash, return true ; } + // Bugs in the cache system can cause files with arbitrary size to be + // requested, causing a division by zero in ftChunkMap when size > 1MB * + // (2^32-1). I thus conservatively check for large size values. + // + if(size >= 1024ull*1024ull*((1ull << 32) - 1)) + { + std::cerr << "FileRequest Error: unexpected size. This is probably a bug." << std::endl; + std::cerr << " name = " << fname << std::endl ; + std::cerr << " flags = " << flags << std::endl ; + std::cerr << " dest = " << dest << std::endl ; + std::cerr << " size = " << size << std::endl ; + return false ; + } + /* If file transfer is not enabled .... * save request for later. This will also * mean that we will have to copy local files,