Merge pull request #2964 from hathach/fix-2939

fix bug introduced by 2939, with correct offset check logic