undo: Fix infinite loop if undo_read_byte returns EOF #2880

Problem:  Corrupt(?) persistent undofile leads to an infinite loop.
Solution: Break out of loop if undo_read_byte returns EOF (cf.
          u_read_undo() which does this too).

backtrace from lldb (@ a743297be2):

    Process 70700 stopped
    * thread 1: tid = 0x147d2d1, 0x00007fff8c8facd7 libsystem_pthread.dylib`__mtx_droplock + 209, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
        frame 0: 0x00007fff8c8facd7 libsystem_pthread.dylib`__mtx_droplock + 209
    libsystem_pthread.dylib`__mtx_droplock + 209:
    -> 0x7fff8c8facd7:  movq   %rcx, -0x50(%rbp)
       0x7fff8c8facdb:  movq   %r8, -0x58(%rbp)
       0x7fff8c8facdf:  movq   %rdx, -0x68(%rbp)
       0x7fff8c8face3:  movq   %r14, -0x60(%rbp)
    (lldb) bt
    * thread 1: tid = 0x147d2d1, 0x00007fff8c8facd7 libsystem_pthread.dylib`__mtx_droplock + 209, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
      * frame 0: 0x00007fff8c8facd7 libsystem_pthread.dylib`__mtx_droplock + 209
        frame 1: 0x00007fff8c8fab4e libsystem_pthread.dylib`pthread_mutex_unlock + 63
        frame 2: 0x00007fff915da2a4 libsystem_c.dylib`getc + 63
        frame 3: 0x000000010e6194b9 nvim`undo_read_byte(bi=0x00007fff5181a838) + 25 at undo.c:1553
        frame 4: 0x000000010e619685 nvim`unserialize_uhp(bi=0x00007fff5181a838, file_name=0x000000000f2e8060) + 421 at undo.c:840
        frame 5: 0x000000010e618abb nvim`u_read_undo(name=0x0000000000000000, hash=0x00007fff5181af80, orig_name=0x000000000f370dd0) + 1579 at undo.c:1363
        frame 6: 0x000000010e4a8db9 nvim`readfile(fname=0x000000000f370dd0, sfname=0x000000000f370dd0, from=0, lines_to_skip=0, lines_to_read=2147483647, eap=0x00007fff5181b6a0, flags=1) + 21017 at fileio.c:
    1961
        frame 7: 0x000000010e3ecc8b nvim`open_buffer(read_stdin=0, eap=0x00007fff5181b6a0, flags=0) + 603 at buffer.c:153
    ...

closes #2879
closes #2880
This commit is contained in:
ssteinbach 2015-06-21 21:45:30 -07:00 committed by Justin M. Keyes
parent 84fcba9b01
commit 6c496db4b7
1 changed files with 1 additions and 1 deletions

View File

@ -891,7 +891,7 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi,
for (;; ) {
int len = undo_read_byte(bi);
if (len == 0) {
if (len == 0 || len == EOF) {
break;
}
int what = undo_read_byte(bi);