stream output corrupt

Bug #820599 reported by Robert Brown
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Critical
Unassigned

Bug Description

SBCL writes the wrong data to output streams when write(2) returns a smaller value
than the total number of bytes requested. I see the problem with I/O to socket streams
where the stream has serve-event equal to NIL.

The bug is in flush-output-buffer in file fd-stream.lisp.
When sb!unix:unix-write returns a value for count that is less than length,
the code loops and tries to write again after waiting for the file descriptor
to become usable. The length for the second write is recomputed
as (- tail head), but head has not been changed to account for the data
already written. The attached patch fixes the problem.

sbcl --version
SBCL 1.0.50

uname -a
Linux paradicsom.nyc.corp.google.com 2.6.32-gg508-generic #gg508-Ubuntu SMP Tue May 24 05:09:12 PDT 2011 x86_64 GNU/Linux

*features*

(:ASDF2 :ASDF :ASDF-UNIX :SB-XREF-FOR-INTERNAL :ANSI-CL :COMMON-LISP :SBCL
 :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
 :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :X86-64 :UNIX :ELF :LINUX :SB-THREAD
 :LARGEFILE :GENCGC :STACK-GROWS-DOWNWARD-NOT-UPWARD :C-STACK-IS-CONTROL-STACK
 :LINKAGE-TABLE :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP
 :RAW-INSTANCE-INIT-VOPS :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :COMPLEX-FLOAT-VOPS :FLOAT-EQL-VOPS :INLINE-CONSTANTS
 :MEMORY-BARRIER-VOPS :OS-PROVIDES-DLOPEN :OS-PROVIDES-DLADDR
 :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T :OS-PROVIDES-GETPROTOBY-R
 :OS-PROVIDES-POLL)

Revision history for this message
Robert Brown (robert-brown) wrote :
  • p Edit (653 bytes, text/plain)
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

commit 40269d0ac711b36151bec69db7a021a28cef41ee
Author: Nikodemus Siivola <email address hidden>
Date: Thu Aug 4 13:31:06 2011 +0300

    fix short writes when not using SERVE-EVENT

      Regression since 1.0.42.43, lp#820599.

      Thanks to Robert Brown.

      If we remain in the loop, we need to update the local HEAD
      variable in the event of a short write.

      NOTE: No test case yet, as this is dependant on the size of kernel
      buffers, and trying to catch the short-write -case is tricky.

Changed in sbcl:
importance: Undecided → Critical
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Patches

Remote bug watches

Bug watches keep track of this bug in other bug trackers.