| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Detecting mime types is a tricky business because we need to balance | 5 // Detecting mime types is a tricky business because we need to balance |
| 6 // compatibility concerns with security issues. Here is a survey of how other | 6 // compatibility concerns with security issues. Here is a survey of how other |
| 7 // browsers behave and then a description of how we intend to behave. | 7 // browsers behave and then a description of how we intend to behave. |
| 8 // | 8 // |
| 9 // HTML payload, no Content-Type header: | 9 // HTML payload, no Content-Type header: |
| 10 // * IE 7: Render as HTML | 10 // * IE 7: Render as HTML |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return content_size >= kMaxBytesToSniff; | 572 return content_size >= kMaxBytesToSniff; |
| 573 } | 573 } |
| 574 | 574 |
| 575 // CRX files (chrome extensions) have a special sniffing algorithm. It is | 575 // CRX files (chrome extensions) have a special sniffing algorithm. It is |
| 576 // tighter than the others because we don't have to match legacy behavior. | 576 // tighter than the others because we don't have to match legacy behavior. |
| 577 if (SniffCRX(content, content_size, url, type_hint, result)) | 577 if (SniffCRX(content, content_size, url, type_hint, result)) |
| 578 return true; | 578 return true; |
| 579 | 579 |
| 580 // Now we look in our large table of magic numbers to see if we can find | 580 // Now we look in our large table of magic numbers to see if we can find |
| 581 // anything that matches the content. | 581 // anything that matches the content. |
| 582 if (SniffForMagicNumbers(content, content_size, result)) | 582 if (SniffForMagicNumbers(content, content_size, result)) { |
| 583 // We should never sniff an octet stream as plain text. There are Unix |
| 584 // binaries with embedded shell scripts that get sniffed incorrectly, |
| 585 // leading to spectacular failures like bug 29354. |
| 586 if (type_hint == "application/octet-stream" && "text/plain" == *result) |
| 587 result->assign("application/octet-stream"); |
| 583 return true; // We've matched a magic number. No more content needed. | 588 return true; // We've matched a magic number. No more content needed. |
| 589 } |
| 584 | 590 |
| 585 // Having failed thus far, we're willing to override unknown mime types and | 591 // Having failed thus far, we're willing to override unknown mime types and |
| 586 // text/plain. | 592 // text/plain. |
| 587 if (hint_is_unknown_mime_type || hint_is_text_plain) { | 593 if (hint_is_unknown_mime_type || hint_is_text_plain) { |
| 588 if (looks_binary) | 594 if (looks_binary) |
| 589 result->assign("application/octet-stream"); | 595 result->assign("application/octet-stream"); |
| 590 else | 596 else |
| 591 result->assign("text/plain"); | 597 result->assign("text/plain"); |
| 592 // We could change our mind if a binary-looking byte appears later in | 598 // We could change our mind if a binary-looking byte appears later in |
| 593 // the content, so we only have enough content if we have the max. | 599 // the content, so we only have enough content if we have the max. |
| 594 return content_size >= kMaxBytesToSniff; | 600 return content_size >= kMaxBytesToSniff; |
| 595 } | 601 } |
| 596 | 602 |
| 597 return have_enough_content; | 603 return have_enough_content; |
| 598 } | 604 } |
| 599 | 605 |
| 600 } // namespace net | 606 } // namespace net |
| OLD | NEW |