[Groonga-commit] groonga/grnxx at ce9f96b [master] Fix bugs of grnxx::storage::View.

Back to archive index

susumu.yata null+****@clear*****
Tue Apr 23 10:46:37 JST 2013


susumu.yata	2013-04-23 10:46:37 +0900 (Tue, 23 Apr 2013)

  New Revision: ce9f96b750504c78c97d2eafb89ee06b3252db8c
  https://github.com/groonga/grnxx/commit/ce9f96b750504c78c97d2eafb89ee06b3252db8c

  Message:
    Fix bugs of grnxx::storage::View.

  Modified files:
    lib/grnxx/storage/view-posix.cpp
    lib/grnxx/storage/view-windows.cpp

  Modified: lib/grnxx/storage/view-posix.cpp (+17 -4)
===================================================================
--- lib/grnxx/storage/view-posix.cpp    2013-04-23 09:50:44 +0900 (7063728)
+++ lib/grnxx/storage/view-posix.cpp    2013-04-23 10:46:37 +0900 (bcdac9c)
@@ -53,16 +53,24 @@ View *ViewImpl::create(File *file, int64_t offset, int64_t size,
     return nullptr;
   }
   if (file) {
-    view->create_file_backed_view(file, offset, size, flags);
+    if (!view->create_file_backed_view(file, offset, size, flags)) {
+      return nullptr;
+    }
   } else {
-    view->create_anonymous_view(size, flags);
+    if (!view->create_anonymous_view(size, flags)) {
+      return nullptr;
+    }
   }
   return view.release();
 }
 
 bool ViewImpl::sync(int64_t offset, int64_t size) {
+  if ((flags_ & VIEW_ANONYMOUS) || (flags_ & VIEW_READ_ONLY)) {
+    GRNXX_WARNING() << "invalid operation: flags = " << flags_;
+    return false;
+  }
   if ((offset < 0) || (offset > size_) || (size > size_) ||
-      ((size >= 0) && ((offset + size) > size_))) {
+      ((size >= 0) && (size > (size_ - offset)))) {
     GRNXX_ERROR() << "invalid argument: offset = " << offset
                   << ", size = " << size << ", view_size = " << size_;
     return false;
@@ -95,11 +103,16 @@ int64_t ViewImpl::size() const {
 bool ViewImpl::create_file_backed_view(File *file, int64_t offset, int64_t size,
                                        ViewFlags flags) {
   const int64_t file_size = file->size();
-  if ((offset < 0) || (offset >= file_size) || (size == 0)) {
+  if ((offset < 0) || (offset >= file_size) ||
+      (size == 0) || (size > file_size) ||
+      ((size > 0) && (size > (file_size - offset)))) {
     GRNXX_ERROR() << "invalid argument: offset = " << offset
                   << ", size = " << size << ", file_size = " << file_size;
     return false;
   }
+  if (size < 0) {
+    size = file_size - offset;
+  }
   if (file->flags() & FILE_READ_ONLY) {
     flags_ |= VIEW_READ_ONLY;
   }

  Modified: lib/grnxx/storage/view-windows.cpp (+17 -4)
===================================================================
--- lib/grnxx/storage/view-windows.cpp    2013-04-23 09:50:44 +0900 (90ca935)
+++ lib/grnxx/storage/view-windows.cpp    2013-04-23 10:46:37 +0900 (34e8a27)
@@ -55,16 +55,24 @@ View *ViewImpl::create(File *file, int64_t offset, int64_t size,
     return nullptr;
   }
   if (file) {
-    view->create_file_backed_view(file, offset, size, flags);
+    if (!view->create_file_backed_view(file, offset, size, flags)) {
+      return nullptr;
+    }
   } else {
-    view->create_anonymous_view(size, flags);
+    if (!view->create_anonymous_view(size, flags)) {
+      return nullptr;
+    }
   }
   return view.release();
 }
 
 bool ViewImpl::sync(int64_t offset, int64_t size) {
+  if ((flags_ & VIEW_ANONYMOUS) || (flags_ & VIEW_READ_ONLY)) {
+    GRNXX_WARNING() << "invalid operation: flags = " << flags_;
+    return false;
+  }
   if ((offset < 0) || (offset > size_) || (size > size_) ||
-      ((size >= 0) && ((offset + size) > size_))) {
+      ((size >= 0) && (size > (size_ - offset)))) {
     GRNXX_ERROR() << "invalid argument: offset = " << offset
                   << ", size = " << size << ", view_size = " << size_;
     return false;
@@ -86,11 +94,16 @@ bool ViewImpl::sync(int64_t offset, int64_t size) {
 bool ViewImpl::create_file_backed_view(File *file, int64_t offset, int64_t size,
                                        ViewFlags flags) {
   const int64_t file_size = file->size();
-  if ((offset < 0) || (offset >= file_size) || (size == 0)) {
+  if ((offset < 0) || (offset >= file_size) ||
+      (size == 0) || (size > file_size) ||
+      ((size > 0) && (size > (file_size - offset)))) {
     GRNXX_ERROR() << "invalid argument: offset = " << offset
                   << ", size = " << size << ", file_size = " << file_size;
     return false;
   }
+  if (size < 0) {
+    size = file_size - offset;
+  }
   if (file->flags() & FILE_READ_ONLY) {
     flags_ |= VIEW_READ_ONLY;
   }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index