Fixed infinite looping on truncated stream objects

My specific comments on this patch are included in a separate email (which also contains an attached test case and further details on the problem and its symptoms)