ImageBuffer: don't write out of allocated memory.

Import the code from cairo implementation that avoids writing before the
allocated memory, when the rectangle has negative coordinates. This
completely mess ups our memory allocator and possibly corrupts other
things, but strangely it didn't completely crash the testsuite. It seems
to have strange side effects, however.