From: aroben@apple.com Date: Wed, 2 Feb 2011 20:33:51 +0000 (+0000) Subject: Encode/decode FormData and FormDataElement objects consistently X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=0c5c8412706458fa789ad9443307a7a03b3d0a11 Encode/decode FormData and FormDataElement objects consistently Fixes WebKit2: Restoring session state that contains form data fails (asserts in Debug build) To prevent this from interfering with WebKit2 testing, it's useful to get this into a build now, even though we don't have an automated test for it yet. Writing a test is covered by . Reviewed by Darin Adler. * history/HistoryItem.cpp: Bump the encoding version, since this patch changes how we encode FormData objects. * platform/network/FormData.cpp: (WebCore::decode): Decode the type from the Decoder, rather than getting it from the default-constructed FormDataElement. Failing to do this meant that all future uses of the Decoder would be reading from an unexpected part of the buffer (i.e., the next decode would start by reading the uint32_t that we forgot to decode here, and so on). We already had code to correctly set the FormDataElement's type based on this decoded type later in the function. (WebCore::FormData::encodeForBackForward): Encode m_identifier as an int64_t, since that matches its type and how we decode it. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@77401 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index dae16cb..036dd56 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,29 @@ +2011-02-02 Adam Roben + + Encode/decode FormData and FormDataElement objects consistently + + Fixes WebKit2: Restoring session state + that contains form data fails (asserts in Debug build) + + To prevent this from interfering with WebKit2 testing, it's useful to get this into a build + now, even though we don't have an automated test for it yet. Writing a test is covered by + . + + Reviewed by Darin Adler. + + * history/HistoryItem.cpp: Bump the encoding version, since this patch changes how we encode + FormData objects. + + * platform/network/FormData.cpp: + (WebCore::decode): Decode the type from the Decoder, rather than getting it from the + default-constructed FormDataElement. Failing to do this meant that all future uses of the + Decoder would be reading from an unexpected part of the buffer (i.e., the next decode would + start by reading the uint32_t that we forgot to decode here, and so on). We already had code + to correctly set the FormDataElement's type based on this decoded type later in the + function. + (WebCore::FormData::encodeForBackForward): Encode m_identifier as an int64_t, since that + matches its type and how we decode it. + 2011-02-02 Dan Winship Reviewed by Martin Robinson. diff --git a/Source/WebCore/history/HistoryItem.cpp b/Source/WebCore/history/HistoryItem.cpp index 3b76943..c698db3 100644 --- a/Source/WebCore/history/HistoryItem.cpp +++ b/Source/WebCore/history/HistoryItem.cpp @@ -40,7 +40,7 @@ namespace WebCore { -const uint32_t backForwardTreeEncodingVersion = 1; +const uint32_t backForwardTreeEncodingVersion = 2; static long long generateSequenceNumber() { diff --git a/Source/WebCore/platform/network/FormData.cpp b/Source/WebCore/platform/network/FormData.cpp index 16f98ad..bdc4b03 100644 --- a/Source/WebCore/platform/network/FormData.cpp +++ b/Source/WebCore/platform/network/FormData.cpp @@ -364,7 +364,9 @@ static void encode(Encoder& encoder, const FormDataElement& element) static bool decode(Decoder& decoder, FormDataElement& element) { - uint32_t type = element.m_type; + uint32_t type; + if (!decoder.decodeUInt32(type)) + return false; switch (type) { case FormDataElement::data: { @@ -432,7 +434,7 @@ void FormData::encodeForBackForward(Encoder& encoder) const encoder.encodeBool(m_hasGeneratedFiles); - encoder.encodeBool(m_identifier); + encoder.encodeInt64(m_identifier); } PassRefPtr FormData::decodeForBackForward(Decoder& decoder)