Bug 1170606 part-7: add short read handling to files not covered by preceding patches. draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Sun, 20 Oct 2019 05:51:05 +0900
changeset 80348 bad0e9ab740aa3e0bba9a93a0c03926071e76973
parent 80347 b10934f4b3ed45522cdcea14d692e278eba29dd4
child 80349 ffedde2375779414f0415a4e38fc064b3ab16563
push id9576
push userishikawa@yk.rim.or.jp
push dateSat, 19 Oct 2019 20:51:19 +0000
treeherdertry-comm-central@4e899dfbba0c [default view] [failures only]
bugs1170606
Bug 1170606 part-7: add short read handling to files not covered by preceding patches.
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
mailnews/news/src/nsNNTPProtocol.cpp
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -1016,16 +1016,25 @@ NS_IMETHODIMP TokenStreamListener::OnDat
     // is causing that to not happen, so as a last-ditch attempt we'll
     // do it here.
     if (!mBuffer) {
       mBuffer = new char[mBufferSize];
       NS_ENSURE_TRUE(mBuffer, NS_ERROR_OUT_OF_MEMORY);
     }
 
     char* buffer = mBuffer;
+    // xxx Since FullyReadStream handles EINTR (hopefully)
+    // [the case of readCount being zero in the following check],
+    // I may want to use FullyReadStream AFTER checking the available size
+    // here.
+    // But checking the available size in advance is an overkill (and
+    // too many system calls) since this is in a loop where short read
+    // seems to be handled (see the comment at the end of the loop:
+    // /* didn't find a delimiter, keep the whole buffer around. */
+    // So I left the ->Read as is.
     rv = aInputStream->Read(buffer + mLeftOverCount, readCount, &readCount);
     if (NS_FAILED(rv)) break;
 
     if (readCount == 0) {
       rv = NS_ERROR_UNEXPECTED;
       NS_WARNING("failed to tokenize");
       break;
     }
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -3945,16 +3945,22 @@ nsresult nsNNTPProtocol::ProcessProtocol
   nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningURL);
   if (inputStream && (!mailnewsurl || !m_nntpServer)) {
     // In these cases, we are going to return since our data is effectively
     // invalid. However, nsInputStream would really rather that we at least read
     // some of our input data (even if not all of it). Therefore, we'll read a
     // little bit.
     char buffer[128];
     uint32_t readData = 0;
+
+    // xxx Looking at the comment above, it is presumed that short
+    // read seems to be acceptable here.
+    // It is not clear we should check for the error of the Read.
+    // Again, it looks we really are not that concerned much.
+    // So I left the code as is.
     inputStream->Read(buffer, 127, &readData);
     buffer[readData] = '\0';
     MOZ_LOG(NNTP, LogLevel::Debug, ("(%p) Ignoring data: %s", this, buffer));
   }
 
   if (!mailnewsurl) return NS_OK;  // probably no data available - it's OK.
 
   if (!m_nntpServer) {