fixed buffer reading for cases in which less data than expected is returned