Bug 1602816 - followup - Fix wrong buffersize passed into EncodingDetector, when guessing attachment charsets. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Tue, 17 Dec 2019 13:58:02 +0200
changeset 37763 fb67882ad9b9175c3116c8fc8ab364f7c7505e57
parent 37762 321b8dd3f296d653fbcd8172bf370caeca5b673e
child 37764 69b26858a2598926d9a8cad4b499b34a19250520
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1602816
Bug 1602816 - followup - Fix wrong buffersize passed into EncodingDetector, when guessing attachment charsets. r=mkmelin
mailnews/base/util/nsMsgUtils.cpp
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -1786,17 +1786,17 @@ NS_MSG_BASE nsresult MsgDetectCharsetFro
 
   // Use detector.
   mozilla::UniquePtr<mozilla::EncodingDetector> detector =
       mozilla::EncodingDetector::Create();
   char buffer[1024];
   numRead = 0;
   while (NS_SUCCEEDED(inputStream->Read(buffer, sizeof(buffer), &numRead))) {
     mozilla::Span<const uint8_t> src =
-        mozilla::AsBytes(mozilla::MakeSpan(buffer, sizeof(buffer)));
+        mozilla::AsBytes(mozilla::MakeSpan(buffer, numRead));
     Unused << detector->Feed(src, false);
     if (numRead == 0) {
       break;
     }
   }
   Unused << detector->Feed(nullptr, true);
   auto encoding = detector->Guess(nullptr, true);
   encoding->Name(aCharset);