Guest User

Untitled

a guest
May 21st, 2011
211
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // assumes we're on a 32-bit system
  2.  
  3. $fp = fopen($large_file, 'rb'); // assuming $large_file is 4GB or more
  4. fseek($fp, PHP_INT_MAX, SEEK_SET);
  5. echo ftell($fp), "\n"; // works as expected (displays value of PHP_INT_MAX)
  6.  
  7. fseek($fp, 1, SEEK_CUR); // call simply fails
  8. echo ftell($fp), "\n"; // (displays value of PHP_INT_MAX)
  9.  
  10. fread($fp, 1); // works okay
  11. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1)
  12. // (one would expect the previous fseek($fp, 1) call to do the same as the fread call, but anyway...)
  13.  
  14. fseek($fp, -1, SEEK_CUR); // works okay
  15. echo ftell($fp), "\n"; // (displays value of PHP_INT_MAX)
  16.  
  17. fread($fp, 1);
  18. fseek($fp, 1, SEEK_CUR); // works okay
  19. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
  20.  
  21. fseek($fp, -1, SEEK_CUR); // doesn't work! I'm guessing there's code to check if the file position would become negative, and deny the call if so
  22. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
  23.  
  24.  
  25. // odd 8192 byte limitation to fseek'ing forward
  26. fseek($fp, 8192, SEEK_CUR); // doesn't work!
  27. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
  28.  
  29. fseek($fp, 1, SEEK_CUR); // also fails!
  30. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX)
  31.  
  32. // restart everything
  33. fseek($fp, PHP_INT_MAX, SEEK_SET);
  34. fread($fp, 1);
  35. fseek($fp, 8191, SEEK_CUR); // this works okay
  36. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191)
  37.  
  38. fseek($fp, 1, SEEK_CUR); // doesn't work!
  39. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191)
  40.  
  41. // it seems that there's some 8K buffer or similar with fseek - we need to "reset" this buffer with an fread to go further
  42. fread($fp, 1);
  43. fseek($fp, 8191, SEEK_CUR); // this now works
  44. echo ftell($fp), "\n"; // (displays value of -PHP_INT_MAX-1+8191*2)
RAW Paste Data