safety check to ensure we dont send out beyond the users buffer

(Imported from upstream's 011ee91105f00cb2465110ce6431b11b51556d08 and
f2ebe2a60eacf3e348898175be82971b57d72327)
1 file changed