The return value of SharedBuffer::createWithContentsOfFile must have valid m_size.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jul 2011 17:29:20 +0000 (17:29 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jul 2011 17:29:20 +0000 (17:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=63313

Patch by Kyusun Kim <maniagoon@company100.net> on 2011-07-07
Reviewed by Eric Seidel.

* platform/posix/SharedBufferPOSIX.cpp:
(WebCore::SharedBuffer::createWithContentsOfFile):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90574 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/posix/SharedBufferPOSIX.cpp

index 74436ba121143152dbc8c70f0ba7c7b486fe63e5..60e359f962d175f92ed96466efaa373a53dea2c4 100644 (file)
@@ -1,3 +1,13 @@
+2011-07-07  Kyusun Kim  <maniagoon@company100.net>
+
+        The return value of SharedBuffer::createWithContentsOfFile must have valid m_size.
+        https://bugs.webkit.org/show_bug.cgi?id=63313
+
+        Reviewed by Eric Seidel.
+
+        * platform/posix/SharedBufferPOSIX.cpp:
+        (WebCore::SharedBuffer::createWithContentsOfFile):
+
 2011-07-07  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/9737435> Re-enable -webkit-column-break-inside: avoid
index 6f66d4d2863fa780599a646b958bfb8928bc5fab..ebd71bfd6b74da328fdeb1ea3d8754e72bdd1008 100644 (file)
@@ -57,17 +57,16 @@ PassRefPtr<SharedBuffer> SharedBuffer::createWithContentsOfFile(const String& fi
         return 0;
     }
 
-    RefPtr<SharedBuffer> result = create();
-    result->m_buffer.grow(bytesToRead);
+    Vector<char> buffer(bytesToRead);
 
     size_t totalBytesRead = 0;
     ssize_t bytesRead;
-    while ((bytesRead = read(fd, result->m_buffer.data() + totalBytesRead, bytesToRead - totalBytesRead)) > 0)
+    while ((bytesRead = read(fd, buffer.data() + totalBytesRead, bytesToRead - totalBytesRead)) > 0)
         totalBytesRead += bytesRead;
 
     close(fd);
 
-    return totalBytesRead == bytesToRead ? result.release() : 0;
+    return totalBytesRead == bytesToRead ? SharedBuffer::adoptVector(buffer) : 0;
 }
 
 } // namespace WebCore