fix a core dump in inputstream and add test case  (Wen Lin <wlin@pivotal.io>)