diff options
-rw-r--r-- | base/file_util_proxy.cc | 2 | ||||
-rw-r--r-- | base/file_util_proxy.h | 1 | ||||
-rw-r--r-- | ppapi/c/ppb_file_io.h | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/quota_file_io.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/quota_file_io.h | 1 | ||||
-rw-r--r-- | webkit/plugins/ppapi/quota_file_io_unittest.cc | 12 |
6 files changed, 24 insertions, 3 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc index 2d5125f..0e4badf 100644 --- a/base/file_util_proxy.cc +++ b/base/file_util_proxy.cc @@ -868,6 +868,8 @@ bool FileUtilProxy::Write( const char* buffer, int bytes_to_write, WriteCallback* callback) { + if (bytes_to_write <= 0) + return false; return Start(FROM_HERE, message_loop_proxy, new RelayWrite(file, offset, buffer, bytes_to_write, callback)); } diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h index 928004a..872da44 100644 --- a/base/file_util_proxy.h +++ b/base/file_util_proxy.h @@ -168,6 +168,7 @@ class BASE_EXPORT FileUtilProxy { // Writes to a file. If |offset| is greater than the length of the file, // |false| is returned. On success, the file pointer is moved to position // |offset + bytes_to_write| in the file. The callback can be NULL. + // |bytes_to_write| must be greater than zero. static bool Write( scoped_refptr<MessageLoopProxy> message_loop_proxy, PlatformFile file, diff --git a/ppapi/c/ppb_file_io.h b/ppapi/c/ppb_file_io.h index 821766d..ca23b95 100644 --- a/ppapi/c/ppb_file_io.h +++ b/ppapi/c/ppb_file_io.h @@ -164,7 +164,7 @@ struct PPB_FileIO { * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon * completion of Read(). * - * @return An The number of bytes read an error code from + * @return An The number of bytes read or an error code from * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was * reached. It is valid to call Read() multiple times with a completion * callback to queue up parallel reads from the file at different offsets. @@ -190,7 +190,9 @@ struct PPB_FileIO { * @return An The number of bytes written or an error code from * <code>pp_errors.h</code>. If the return value is 0, then end-of-file was * reached. It is valid to call Write() multiple times with a completion - * callback to queue up parallel writes to the file at different offsets. + * callback to queue up parallel writes to the file at different offsets. If + * bytes_to_write is less than or equal to zero, return value is + * PP_ERROR_FAILED. */ int32_t (*Write)(PP_Resource file_io, int64_t offset, @@ -243,4 +245,3 @@ struct PPB_FileIO { */ #endif /* PPAPI_C_PPB_FILE_IO_H_ */ - diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc index d5af70b..2e628c7 100644 --- a/webkit/plugins/ppapi/quota_file_io.cc +++ b/webkit/plugins/ppapi/quota_file_io.cc @@ -4,6 +4,8 @@ #include "webkit/plugins/ppapi/quota_file_io.h" +#include <algorithm> + #include "base/stl_util.h" #include "base/message_loop_proxy.h" #include "base/task.h" @@ -222,6 +224,8 @@ QuotaFileIO::~QuotaFileIO() { bool QuotaFileIO::Write( int64_t offset, const char* buffer, int32_t bytes_to_write, WriteCallback* callback) { + if (bytes_to_write <= 0) + return false; WriteOperation* op = new WriteOperation( this, false, offset, buffer, bytes_to_write, callback); return RegisterOperationForQuotaChecks(op); diff --git a/webkit/plugins/ppapi/quota_file_io.h b/webkit/plugins/ppapi/quota_file_io.h index bbd1b36..1ee3188 100644 --- a/webkit/plugins/ppapi/quota_file_io.h +++ b/webkit/plugins/ppapi/quota_file_io.h @@ -35,6 +35,7 @@ class QuotaFileIO { // Performs write or setlength operation with quota checks. // Returns true when the operation is successfully dispatched. + // |bytes_to_write| must be geater than zero. // |callback| will be dispatched when the operation completes. // Otherwise it returns false and |callback| will not be dispatched. // |callback| will not be dispatched either when this instance is diff --git a/webkit/plugins/ppapi/quota_file_io_unittest.cc b/webkit/plugins/ppapi/quota_file_io_unittest.cc index 1e0b360..79a4637 100644 --- a/webkit/plugins/ppapi/quota_file_io_unittest.cc +++ b/webkit/plugins/ppapi/quota_file_io_unittest.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include <deque> +#include <limits> +#include <string> #include "base/basictypes.h" #include "base/memory/scoped_callback_factory.h" @@ -115,6 +117,16 @@ class QuotaFileIOTest : public PpapiUnittest { } void WriteTestBody(bool will_operation) { + // Attempt to write zero bytes. + EXPECT_FALSE(quota_file_io_->Write(0, "data", 0, + callback_factory_.NewCallback( + &QuotaFileIOTest::DidWrite))); + // Attempt to write negative number of bytes. + EXPECT_FALSE(quota_file_io_->Write(0, "data", + std::numeric_limits<int32_t>::min(), + callback_factory_.NewCallback( + &QuotaFileIOTest::DidWrite))); + quota_plugin_delegate()->set_available_space(100); std::string read_buffer; |