apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Evgeny Kotkov <evgeny.kot...@visualsvn.com>
Subject [PATCH] Fix apr_file_trunc() for buffered files on Windows and Unix
Date Tue, 28 Feb 2017 09:38:20 GMT
Hi everyone,

This patch fixes two issues with apr_file_trunc() for buffered files:

 - The Win32 implementation incorrectly flushes the buffered writes _after_
   truncating a file.  Such files will have unexpected data written after
   the position at which they should've been truncated.  (Under Unix,
   this issue has been fixed in https://svn.apache.org/r1044440)

 - Both Win32 and Unix implementations incorrectly keep the data read into
   a buffer after the file is truncated.  Thus, reading from a file after
   apr_file_trunc() can return invalid data from the previous file offset.

Log message:
[[[
Fix two issues with apr_file_trunc() for buffered files:

 - The Win32 implementation incorrectly flushes the buffered writes _after_
   truncating a file.  Such files will have unexpected data written after
   the position at which they should've been truncated.  (Under Unix,
   this issue has been fixed in https://svn.apache.org/r1044440)

 - Both Win32 and Unix implementations incorrectly keep the data read into
   a buffer after the file is truncated.  Thus, reading from a file after
   apr_file_trunc() can return invalid data from the previous file offset.

* file_io/win32/seek.c
  (apr_file_trunc): Flush the write buffer or discard the read buffer
   before truncating.  Propely update the internal file offset (filePtr)
   and the eof_hit marker.

* file_io/unix/seek.c
  (apr_file_trunc): Discard the read buffer before truncating.

* test/testfile.c
  (test_file_trunc): Extend the checks.  Factor out part of this test...
  (test_file_trunc_buffered_write): ...into this new test.
  (test_file_trunc_buffered_write2, test_file_trunc_buffered_read): New tests.
  (testfile): Run the new tests.

Patch by: Evgeny Kotkov <evgeny.kotkov {at} visualsvn.com>
]]]


Regards,
Evgeny Kotkov

Mime
View raw message