There is a bug in the SoX pulseaudio handler, that leads to an inconsistent behaviour of SoX: with ALSA, OSS etc. when a write of zero length is performed nothing happens, with PulseAudio instead SoX quits when a zero length write is performed. This is because pa_simple_write() returns an error whenever the input buffer length is zero.
As a result, example3.c from the SoX source code fails if one tries to substitute alsa with pulseaudio (tested with an ogg/vorbis file). The solution is to modify write_samples from pulseaudio.c so that it behaviours exactly like ALSA, i.e. it returns 0 when 0 is the length of the write. This can be achieved by simply adding something like if (nsamp == 0) return 0; before the call to pa_simple_write(). As far as I tested it there are not downturns to this approach.
NOTE: if one tries to perform a zero length write (i.e. len is zero) with the ALSA handler, the for cycle never executes its code, because the condition is (done = 0; done < len; done += n), so it reaches the end of the function where the line return len; is executed, i.e. it just returns zero when len is zero.
A patch that solves the problem:
Fixed.