From 3ad2833dd97de6556f6a2c82623c8d4ca402e605 Mon Sep 17 00:00:00 2001 From: Sujith Haridasan Date: Thu, 12 May 2022 18:45:17 +0530 Subject: [PATCH] MDL-74718 webdav: correct the loop when reading chunks Adjusted the condition while reading the streams in chunks. Read till the end to make sure we have got all the data. Else we might not get all the data to show in file picker. --- lib/webdavlib.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/webdavlib.php b/lib/webdavlib.php index c1307152233..ea4493aa6fa 100644 --- a/lib/webdavlib.php +++ b/lib/webdavlib.php @@ -1561,7 +1561,7 @@ EOD; $chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($chunk)); $chunk .= fread($this->sock, $chunk_size); $this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($chunk)); - } while ($mod == $max_chunk_size); + } while (strlen($chunk) < $matches[1]); } self::update_file_or_buffer($chunk, $fp, $buffer); break; @@ -1586,11 +1586,7 @@ EOD; self::update_file_or_buffer($chunk, $fp, $buffer); $loadsize += strlen($chunk); $this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . $loadsize); - } while ($mod == $max_chunk_size); - if ($loadsize < $matches[1]) { - $chunk = fread($this->sock, $matches[1] - $loadsize); - self::update_file_or_buffer($chunk, $fp, $buffer); - } + } while ($matches[1] > $loadsize); break; // check for 204 No Content