bugs: fix dataLen calculation, avoid EOF when dealing with small pics

Hi,

I think I fixed a couple of bugs we stumbled upon because our test cases involve tiny pics.

I tried to stay the least intrusive possible so they may not be the best fixes and you might want to rework that. But it should give you an idea of the problem.

You can find examples of the small pics I'm talking about here:
http://camlistore.org/code/?p=camlistore.git;a=tree;f=pkg/images/testdata;hb=HEAD