is this a bug or a feature of pipe?

It is a bug in your code.  When you do buf[n] = 0 in the last while
loop, you are writing past the end of buf.  This causes pfd[0] to
become 0 and so the next read is actually from stdin.  Making buf
larger "fixes" the problem because n=256 becomes a valid index.

--
Cheers,
Alex Musolino