Be more aggressive when looking for the termination boundary
authorGustavo Noronha Silva <gns@gnome.org>
Mon, 8 Oct 2012 20:10:19 +0000 (17:10 -0300)
committerGustavo Noronha Silva <gns@gnome.org>
Mon, 15 Oct 2012 12:59:54 +0000 (09:59 -0300)
Turns out some servers may send line feeds and carriage return after the final
boundary. That's the case for the following WebKit LayoutTest:

    http/tests/multipart/load-last-non-html-frame.php

https://bugzilla.gnome.org/show_bug.cgi?id=685752

libsoup/soup-multipart-input-stream.c

index b1738ef..0867f84 100644 (file)
@@ -378,8 +378,10 @@ soup_multipart_input_stream_read_headers (SoupMultipartInputStream  *multipart,
                        got_boundary = TRUE;
 
                        /* Now check for possible multipart termination. */
-                       buf = &read_buf[nread - 2];
-                       if (nread >= 2 && !memcmp (buf, "--", 2)) {
+                       buf = &read_buf[nread - 4];
+                       if ((nread >= 4 && !memcmp (buf, "--\r\n", 4)) ||
+                           (nread >= 3 && !memcmp (buf + 1, "--\n", 3)) ||
+                           (nread >= 3 && !memcmp (buf + 2, "--", 2))) {
                                g_byte_array_set_size (priv->meta_buf, 0);
                                return FALSE;
                        }