fix memory boundary checking. legal access: addr+len<=mem_size; illegal access: addr+len>mem_size.