Copy upstream change to fix reading data after null bytes