When the "read" callback returns less than the requested number of bytes (e.g. always "1"), libFLAC may trigger an assertion failure inside FLAC__bitreader_read_rice_signed_block(), this is bitreader.c:1074 in flac-1.2.1.tar.gz.
Without --enable-debug, this leads to "sync lost" errors.
Problem is that the function miscalculates the number of bits which were already consumed, when only a few bytes (words==0) are available. When the stop bit is not present in these bytes, the code adds "end" to "cbits":
cbits += end;
This however *always* overflows the "cbits" variable if it was non-zero: "end" is the total number of bits available, and "cbits" is the number of those which were already consumed. "cbits+end" is beyond the defined data buffer. What was probably meant was a simple assignment, instead of an addition. Please verify the attached patch; I have just read your code base for the first time, I might be wrong.