Fix readRect/writeRect bug