diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index 52771a23f3f5eef0c85ad08da6bb3695c9c0c6cf..92769641c5a0192bd63b65712b3840c8d4efa1f0 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -1681,6 +1681,12 @@ bool sbbs_t::editmsg(smb_t* smb, smbmsg_t *msg)
 		smb_close_da(smb);
 	}
 
+	if(offset < 0) {
+		smb_unlocksmbhdr(smb);
+		errormsg(WHERE,ERR_ALLOC,msgtmp,length);
+		return false;
+	}
+
 	msg->hdr.offset=(uint32_t)offset;
 	if((file=open(msgtmp,O_RDONLY|O_BINARY))==-1
 		|| (instream=fdopen(file,"rb"))==NULL) {