[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
andersca at apple.com
andersca at apple.com
Wed Dec 22 13:34:43 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit ff2089cf02f5979b54a73fba0dc63ad4f0a8bb37
Author: andersca at apple.com <andersca at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Sep 20 19:59:54 2010 +0000
Don't use bufferIsLargeEnoughToContain for Vectors with variable sized elements
https://bugs.webkit.org/show_bug.cgi?id=46109
Reviewed by Adam Roben.
Add a new VectorArgumentCoder class template, with specializations based on whether the
element is fixed size or not. Then update the ArgumentEncoder<Vector<T>> specialization to choose the
right VectorArgumentCoder specialization. To determine this, we use the "IsArithmetic" type trait,
which holds true for all integer types and all floating point types.
* Platform/CoreIPC/ArgumentCoders.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67874 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 33b2a8f..196a4f5 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,17 @@
+2010-09-20 Anders Carlsson <andersca at apple.com>
+
+ Reviewed by Adam Roben.
+
+ Don't use bufferIsLargeEnoughToContain for Vectors with variable sized elements
+ https://bugs.webkit.org/show_bug.cgi?id=46109
+
+ Add a new VectorArgumentCoder class template, with specializations based on whether the
+ element is fixed size or not. Then update the ArgumentEncoder<Vector<T>> specialization to choose the
+ right VectorArgumentCoder specialization. To determine this, we use the "IsArithmetic" type trait,
+ which holds true for all integer types and all floating point types.
+
+ * Platform/CoreIPC/ArgumentCoders.h:
+
2010-09-20 Enrica Casucci <enrica at apple.com>
Reviewed by Sam Weinig.
diff --git a/WebKit2/Platform/CoreIPC/ArgumentCoders.h b/WebKit2/Platform/CoreIPC/ArgumentCoders.h
index 6df8424..37c2f25 100644
--- a/WebKit2/Platform/CoreIPC/ArgumentCoders.h
+++ b/WebKit2/Platform/CoreIPC/ArgumentCoders.h
@@ -30,6 +30,7 @@
#include "ArgumentEncoder.h"
#include <utility>
#include <wtf/HashMap.h>
+#include <wtf/TypeTraits.h>
#include <wtf/Vector.h>
namespace CoreIPC {
@@ -69,7 +70,9 @@ template<typename T, typename U> struct ArgumentCoder<std::pair<T, U> > {
}
};
-template<typename T> struct ArgumentCoder<Vector<T> > {
+template<bool fixedSizeElements, typename T> struct VectorArgumentCoder;
+
+template<typename T> struct VectorArgumentCoder<false, T> {
static void encode(ArgumentEncoder* encoder, const Vector<T>& vector)
{
encoder->encodeUInt64(vector.size());
@@ -83,7 +86,39 @@ template<typename T> struct ArgumentCoder<Vector<T> > {
if (!decoder->decodeUInt64(size))
return false;
- // Before allocating the vector, make sure that the decoder buffer is big enough.
+ Vector<T> tmp;
+ for (size_t i = 0; i < size; ++i) {
+ T element;
+ if (!decoder->decode(element))
+ return false;
+
+ tmp.append(element);
+ }
+
+ tmp.shrinkToFit();
+ vector.swap(tmp);
+ return true;
+ }
+};
+
+template<typename T> struct VectorArgumentCoder<true, T> {
+ static void encode(ArgumentEncoder* encoder, const Vector<T>& vector)
+ {
+ encoder->encodeUInt64(vector.size());
+ // FIXME: If we could tell the encoder to align the buffer, we could just do an encodeBytes here.
+ for (size_t i = 0; i < vector.size(); ++i)
+ encoder->encode(vector[i]);
+ }
+
+ static bool decode(ArgumentDecoder* decoder, Vector<T>& vector)
+ {
+ uint64_t size;
+ if (!decoder->decodeUInt64(size))
+ return false;
+
+ // Since we know the total size of the elements, we can allocate the vector in
+ // one fell swoop. Before allocating we must however make sure that the decoder buffer
+ // is big enough.
if (!decoder->bufferIsLargeEnoughToContain<T>(size)) {
decoder->markInvalid();
return false;
@@ -105,6 +140,8 @@ template<typename T> struct ArgumentCoder<Vector<T> > {
}
};
+template<typename T> struct ArgumentCoder<Vector<T> > : VectorArgumentCoder<WTF::IsArithmetic<T>::value, T> { };
+
// Specialization for Vector<uint8_t>
template<> struct ArgumentCoder<Vector<uint8_t> > {
static void encode(ArgumentEncoder* encoder, const Vector<uint8_t>& vector)
diff --git a/WebKit2/Platform/CoreIPC/ArgumentDecoder.h b/WebKit2/Platform/CoreIPC/ArgumentDecoder.h
index 42f359c..dee0152 100644
--- a/WebKit2/Platform/CoreIPC/ArgumentDecoder.h
+++ b/WebKit2/Platform/CoreIPC/ArgumentDecoder.h
@@ -29,6 +29,7 @@
#include "ArgumentCoder.h"
#include "Attachment.h"
#include <wtf/Deque.h>
+#include <wtf/TypeTraits.h>
#include <wtf/Vector.h>
namespace CoreIPC {
@@ -58,6 +59,8 @@ public:
template<typename T>
bool bufferIsLargeEnoughToContain(size_t numElements) const
{
+ COMPILE_ASSERT(WTF::IsArithmetic<T>::value, type_must_have_known_encoded_size);
+
if (numElements > std::numeric_limits<size_t>::max() / sizeof(T))
return false;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list