Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: Source/core/loader/DocumentLoader.cpp

Issue 125403003: Fix crash on incorrectly formatted MHTML documents (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (!responseEndTime) 279 if (!responseEndTime)
280 responseEndTime = m_timeOfLastDataReceived; 280 responseEndTime = m_timeOfLastDataReceived;
281 if (!responseEndTime) 281 if (!responseEndTime)
282 responseEndTime = monotonicallyIncreasingTime(); 282 responseEndTime = monotonicallyIncreasingTime();
283 timing()->setResponseEnd(responseEndTime); 283 timing()->setResponseEnd(responseEndTime);
284 284
285 commitIfReady(); 285 commitIfReady();
286 if (!frameLoader()) 286 if (!frameLoader())
287 return; 287 return;
288 288
289 if (isArchiveMIMEType(m_response.mimeType())) { 289 if (!maybeCreateArchive()) {
290 createArchive();
291 } else {
292 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that 290 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that
293 // DocumentWriter::begin() gets called and creates the Document. 291 // DocumentWriter::begin() gets called and creates the Document.
294 if (!m_writer) 292 if (!m_writer)
295 commitData(0, 0); 293 commitData(0, 0);
296 } 294 }
297 295
298 endWriting(m_writer.get()); 296 endWriting(m_writer.get());
299 297
300 if (!m_mainDocumentError.isNull()) 298 if (!m_mainDocumentError.isNull())
301 return; 299 return;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 if (doc->isDelayingLoadEvent() && !doc->loadEventFinished()) 636 if (doc->isDelayingLoadEvent() && !doc->loadEventFinished())
639 return true; 637 return true;
640 if (doc->processingLoadEvent()) 638 if (doc->processingLoadEvent())
641 return true; 639 return true;
642 if (doc->hasActiveParser()) 640 if (doc->hasActiveParser())
643 return true; 641 return true;
644 } 642 }
645 return frameLoader()->subframeIsLoading(); 643 return frameLoader()->subframeIsLoading();
646 } 644 }
647 645
648 void DocumentLoader::createArchive() 646 bool DocumentLoader::maybeCreateArchive()
649 { 647 {
648 // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0.
649 if (!isArchiveMIMEType(m_response.mimeType()))
650 return false;
651
650 ASSERT(m_mainResource); 652 ASSERT(m_mainResource);
651 m_archive = MHTMLArchive::create(m_response.url(), m_mainResource->resourceB uffer()); 653 m_archive = MHTMLArchive::create(m_response.url(), m_mainResource->resourceB uffer());
652 RELEASE_ASSERT(m_archive); 654 // Invalid MHTML.
655 if (!m_archive || !m_archive->mainResource()) {
656 m_archive.clear();
657 return false;
658 }
653 659
654 addAllArchiveResources(m_archive.get()); 660 addAllArchiveResources(m_archive.get());
655 ArchiveResource* mainResource = m_archive->mainResource(); 661 ArchiveResource* mainResource = m_archive->mainResource();
656 662
657 // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so 663 // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
658 // relative URLs are resolved properly. 664 // relative URLs are resolved properly.
659 ensureWriter(mainResource->mimeType(), m_archive->mainResource()->url()); 665 ensureWriter(mainResource->mimeType(), m_archive->mainResource()->url());
660 666
661 commitData(mainResource->data()->data(), mainResource->data()->size()); 667 commitData(mainResource->data()->data(), mainResource->data()->size());
668 return true;
662 } 669 }
663 670
664 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive) 671 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive)
665 { 672 {
666 ASSERT(archive); 673 ASSERT(archive);
667 if (!m_archiveResourceCollection) 674 if (!m_archiveResourceCollection)
668 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection); 675 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection);
669 m_archiveResourceCollection->addAllResources(archive); 676 m_archiveResourceCollection->addAllResources(archive);
670 } 677 }
671 678
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) 895 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt)
889 { 896 {
890 m_frame->loader().stopAllLoaders(); 897 m_frame->loader().stopAllLoaders();
891 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true); 898 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, m_writer ? m_writer ->encodingWasChosenByUser() : false, true);
892 if (!source.isNull()) 899 if (!source.isNull())
893 m_writer->appendReplacingData(source); 900 m_writer->appendReplacingData(source);
894 endWriting(m_writer.get()); 901 endWriting(m_writer.get());
895 } 902 }
896 903
897 } // namespace WebCore 904 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698