diff --git a/dbms/src/IO/WriteBufferAIO.cpp b/dbms/src/IO/WriteBufferAIO.cpp index 440d9ff0898e1bf363442ff7914e7aba5540a1db..356dd3671e7b4c04bed8097605788cd68942c333 100644 --- a/dbms/src/IO/WriteBufferAIO.cpp +++ b/dbms/src/IO/WriteBufferAIO.cpp @@ -177,17 +177,16 @@ void WriteBufferAIO::waitForAIOCompletion() is_pending_write = false; - if (events[0].res < 0) + off_t bytes_written = events[0].res; + if ((bytes_written < 0) || (static_cast(bytes_written) < flush_buffer.offset())) { got_exception = true; throw Exception("Asynchronous write error on file " + filename, ErrorCodes::AIO_WRITE_ERROR); } - - size_t bytes_written = static_cast(events[0].res); - if (bytes_written < flush_buffer.offset()) + if (pos_in_file > (std::numeric_limits::max() - bytes_written)) { got_exception = true; - throw Exception("Asynchronous write error on file " + filename, ErrorCodes::AIO_WRITE_ERROR); + throw Exception("File position overflowed", ErrorCodes::LOGICAL_ERROR); } pos_in_file += bytes_written;