Bug #1397 Call to my_chsize fails on win32 when the argument newlength is 0
Submitted: 25 Sep 2003 3:44 Modified: 15 Oct 2003 23:12
Reporter: Joakim Ahlen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:mysql-4.0.15 OS:Windows (Windows XP)
Assigned to: Bugs System CPU Architecture:Any

[25 Sep 2003 3:44] Joakim Ahlen
Description:
For unknown reasons, the function my_chsize sometimes get called with the argument newlength set to 0. When this happened on a win32 system, the consequence would be that the SetFilePointer() would be called with both lDistanceToMove and lpDistanceToMoveHigh  set to 0. This caused SetFilePointer() to fail with error code 2. 

The problem occurred as follows:
---------------------------------------
mysql> delete from property;
ERROR 14: Can't change size of file (Errcode: 2)
mysql>
---------------------------------------

The cause for this error was not thouroughly investigated due to lack of time. Same goes for the reproducibility. 

How to repeat:
The error only occurred on DELETE-statements during my testing, and it was to some extent random, since some tables could be emptied without a problem. It seemed to me that the error started occurring when that table previously had been subject to a lot of questions being made. (Too much and too complicated to paste here…). During my testing, more than one open connection to the same database was open.

Suggested fix:
The correct way to solve this problem would be to make sure that my_chsize was never called with newlength = 0, however a quick fix for me was to insert the following code in the beginning of the my_chsize function:

  if (newlength == 0) {
	  DBUG_RETURN(0);
  }

I have no idea if this fix causes other problems or whether or not the right action to take is to simply ignore the call to my_chsize of newlength = 0. That’s up to you. It seemed to be working for me though.
[25 Sep 2003 4:35] Joakim Ahlen
I forgot to add, the affected file is mysys\my_chsize.c
[30 Sep 2003 11:59] MySQL Verification Team
Thank you for the bug report I verified that the function SetFilePointer() has
substituted SetFilePointerEx() and both handle the returns error in different
ways, so even don't exists an error SetFilePointer() is returning like it.

I reported this for our developer team and waiting their conclusion.
[15 Oct 2003 23:12] MySQL Verification Team
Thank you for the bug report, this issue was already fixed with the
  ChangeSet:
  1.1573 03/10/15 21:41:13 monty@mashka.mysql.fi +10 -0
  Fixed chsize() problem on windows