- "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ")",
- ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount);
+ "afp_read(fork: %" PRIu16 " [%s], off: %" PRIu64 ", len: %" PRIu64 ", size: %" PRIu64 ")",
+ ofork->of_refnum, (ofork->of_flags & AFPFORK_DATA) ? "data" : "reso", offset, reqcount, size);
+
+ if (offset >= size) {
+ err = AFPERR_EOF;
+ goto afp_read_err;
+ }
+
+ /* subtract off the offset */
+ if (reqcount + offset > size) {
+ reqcount = size - offset;
+ err = AFPERR_EOF;
+ }