+ do {
+ if (img->fops->read(buf, sizeof buf, img->f) != sizeof buf) {
+ if (img->fops->eof(img->f))
+ lbx_error_raise(LBX_EEOF);
+ return -1;
+ }
+
+ length = unpack_16_le(buf+0);
+ offset = unpack_16_le(buf+2);
+
+ if (length == 0) {
+ if (offset == 1000) {
+ img->read_state = READ_STATE_DONE;
+ return 0;
+ } else if (offset > img->pub.height - img->currenty) {
+ lbx_error_raise(LBX_EFORMAT);
+ return -1;
+ }
+
+ img->currenty += offset;
+ img->currentx = 0;
+ }
+ } while (length == 0);
+
+ if (offset > img->pub.width - img->currentx) {
+ lbx_error_raise(LBX_EFORMAT);
+ return -1;
+ }
+ img->currentx += offset;
+
+ if (length > img->pub.width - img->currentx) {
+ lbx_error_raise(LBX_EFORMAT);