From b824abd4a1f0a1458e89c5f023902687ee1730e9 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Mon, 10 Oct 2011 20:25:47 +0200 Subject: [PATCH] Fixes a problem with parsing overlong changelog lines When an overlong edit summary was given for an edit, the resulting changelog line could be longer than the chunk that is handled in the changelog reader (8192 bytes) causing the reader to abort the operation. This meant that old revisions where no longer accessible. This patch fixes the reader (it continues reading chunks until a full line is found). However, limiting the summary makes sense and will be added in another patch. --- inc/changelog.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/inc/changelog.php b/inc/changelog.php index fea39f9f7..3162df01a 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -454,8 +454,9 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { } $num = max($num, 0); $chunk_size = max($chunk_size, 0); - if ($first<0) { $first = 0; } - else if (!$media && @file_exists(wikiFN($id)) || $media && @file_exists(mediaFN($id))) { + if ($first<0) { + $first = 0; + } else if (!$media && @file_exists(wikiFN($id)) || $media && @file_exists(mediaFN($id))) { // skip current revision if the page exists $first = max($first+1, 0); } @@ -476,13 +477,21 @@ function getRevisions($id, $first, $num, $chunk_size=8192, $media=false) { $finger = max($tail-$chunk_size, 0); while ($count<$num+$first) { fseek($fp, $finger); + $nl = $finger; if ($finger>0) { fgets($fp); // slip the finger forward to a new line - $finger = ftell($fp); + $nl = ftell($fp); + } + + // was the chunk big enough? if not, take another bite + if($nl > 0 && $tail <= $nl){ + $finger = max($finger-$chunk_size, 0); + continue; + }else{ + $finger = $nl; } // read chunk - if ($tail<=$finger) { break; } $chunk = ''; $read_size = max($tail-$finger, 0); // found chunk size $got = 0; -- GitLab