Guangcun Li created RATIS-2717:
----------------------------------

             Summary: Incorrect size accounting in 
SegmentedRaftLogReader.decodeEntry()
                 Key: RATIS-2717
                 URL: https://issues.apache.org/jira/browse/RATIS-2717
             Project: Ratis
          Issue Type: Bug
          Components: RaftLog
            Reporter: Guangcun Li


h3. Incorrect size accounting in SegmentedRaftLogReader.decodeEntry()

{{decodeEntry()}} checks the serialized entry size against {{{}maxOpSize{}}}, 
but also applies the same limit to reads that include the varint length prefix 
and the four-byte checksum.

Let {{S}} be the serialized entry size and {{V}} the length-prefix size. A 
complete on-disk record occupies {{V + S + 4}} bytes.
 * With {{{}maxOpSize = S{}}}, the entry-size check passes, but 
{{checkBufferSize(V + S, maxOpSize)}} fails with an 
{{{}IllegalStateException{}}}, which is wrapped in an {{{}IOException{}}}.
 * With {{{}maxOpSize = V + S{}}}, the prefix and entry can be read, but 
reading the checksum exceeds the limit.
 * With {{{}maxOpSize = V + S + 4{}}}, the same entry is read successfully.

Account for the length prefix in the temporary-buffer bound, and for both the 
prefix and checksum in the read limit and mark range, while retaining the 
serialized-entry size check.
h3. Verification
 * A reproducing test writes a valid entry using 
{{SegmentedRaftLogOutputStream}} and verifies the three cases above.
 * A regression test expecting a successful read with {{maxOpSize = S}} fails 
before the fix and passes after it.
 * All six tests in {{TestRaftLogReadWrite}} pass with the fix in a focused 
javac/JUnit run.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to