https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-05-22T09:54:28ZRuby Issue Tracking SystemBackport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394692013-05-22T09:54:28Zphasis68 (Heesob Park)phasis@gmail.com
<ul></ul><p>This bug is due to the invalid error checking of SetFilePointer function.<br>
The constant INVALID_SET_FILE_POINTER is defined as (DWORD)-1 and is same to 0xFFFFFFFF(4294967295).</p>
<p>I can see the following sentences in the documentation of SetFilePointer function:<br>
Because INVALID_SET_FILE_POINTER is a valid value for the low-order DWORD of the new file pointer, you must check both the return value of the function and the error code returned by GetLastError to determine whether or not an error has occurred. If an error has occurred, the return value of SetFilePointer is INVALID_SET_FILE_POINTER and GetLastError returns a value other than NO_ERROR.</p>
<p>Refer to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541(v=vs.85).aspx" class="external">http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541(v=vs.85).aspx</a></p>
<p>Here is a patch:<br>
diff --git a/win32.c b/win32.c.new<br>
index 318af2f..79a49d4 100644<br>
--- a/win32.c<br>
+++ b/win32.c.new<br>
@@ -6084,8 +6084,8 @@ rb_w32_read(int fd, void *buf, size_t size)<br>
#ifndef INVALID_SET_FILE_POINTER<br>
#define INVALID_SET_FILE_POINTER ((DWORD)-1)<br>
#endif</p>
<ul>
<li>
<pre><code> if (low == INVALID_SET_FILE_POINTER) {
</code></pre>
</li>
<li>
<pre><code> errno = map_errno(GetLastError());
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> if (low == INVALID_SET_FILE_POINTER && (err = GetLastError()) != NO_ERROR) {
</code></pre>
</li>
<li>
<pre><code> errno = map_errno(err);
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
return -1;
}
</code></pre>
</li>
</ul>
<p>@@ -6228,8 +6228,8 @@ rb_w32_write(int fd, const void *buf, size_t size)<br>
#ifndef INVALID_SET_FILE_POINTER<br>
#define INVALID_SET_FILE_POINTER ((DWORD)-1)<br>
#endif</p>
<ul>
<li>
<pre><code> if (low == INVALID_SET_FILE_POINTER) {
</code></pre>
</li>
<li>
<pre><code> errno = map_errno(GetLastError());
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> if (low == INVALID_SET_FILE_POINTER && (err = GetLastError()) != NO_ERROR) {
</code></pre>
</li>
<li>
<pre><code> errno = map_errno(err);
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
return -1;
}
</code></pre>
</li>
</ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394772013-05-22T15:19:04Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r40888.<br>
Oleg, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>win32.c: check error of SetFilePointer</p>
<ul>
<li>win32/win32.c (setup_overlapped): check the error code in addition<br>
to the result of SetFilePointer() to determine if an error occurred,<br>
because INVALID_SET_FILE_POINTER is a valid value.<br>
<a href="/issues/8431">[ruby-core:55098]</a> [Bug <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: File.read() crash on Win32SP3 32bit (Closed)" href="https://bugs.ruby-lang.org/issues/8431">#8431</a>]</li>
</ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394782013-05-22T15:21:01Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Backport</strong> changed from <i>1.9.3: UNKNOWN, 2.0.0: UNKNOWN</i> to <i>1.9.3: REQUIRED, 2.0.0: REQUIRED</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394792013-05-22T15:21:20Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Assignee</strong> changed from <i>windows</i> to <i>nagachika (Tomoyuki Chikanaga)</i></li><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Backport</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>Backport200</i></li><li><strong>Category</strong> deleted (<del><i>platform/windows</i></del>)</li><li><strong>Status</strong> changed from <i>Closed</i> to <i>Assigned</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394802013-05-22T16:47:04Zphasis68 (Heesob Park)phasis@gmail.com
<ul></ul><p>The change set r40888 is not complete.<br>
As I pointed out the above patch, there are two SetFilePointer checking.<br>
The invalid SetFilePointer check is still remains in the rb_w32_write function.</p>
<p>Here is write part segfault.</p>
<p>C:\Users\phasis>irb<br>
DL is deprecated, please use Fiddle<br>
irb(main):001:0> f = File.open('a','wb')<br>
=> #<a href="File:a" class="external">File:a</a><br>
irb(main):002:0> f.seek(0xffffffff)<br>
=> 0<br>
irb(main):003:0> f.write('1')<br>
=> 1<br>
irb(main):004:0> f.tell<br>
(irb):4: [BUG] rb_sys_fail() - errno == 0<br>
ruby 2.0.0p195 (2013-05-14) [i386-mingw32]</p>
<p>-- Control frame information -----------------------------------------------<br>
c:0019 p:---- s:0075 e:000074 CFUNC :tell<br>
c:0018 p:0006 s:0072 e:000071 EVAL (irb):4 [FINISH]<br>
c:0017 p:---- s:0070 e:000069 CFUNC :eval<br>
c:0016 p:0024 s:0063 e:000062 METHOD C:/Ruby200/lib/ruby/2.0.0/irb/workspace.rb:<br>
86<br>
c:0015 p:0025 s:0056 e:000054 METHOD C:/Ruby200/lib/ruby/2.0.0/irb/context.rb:38<br>
0<br>
c:0014 p:0022 s:0050 e:000049 BLOCK C:/Ruby200/lib/ruby/2.0.0/irb.rb:492<br>
c:0013 p:0040 s:0042 e:000041 METHOD C:/Ruby200/lib/ruby/2.0.0/irb.rb:624<br>
c:0012 p:0009 s:0037 e:000036 BLOCK C:/Ruby200/lib/ruby/2.0.0/irb.rb:489<br>
c:0011 p:0118 s:0033 e:000032 BLOCK C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:2<br>
47 [FINISH]<br>
c:0010 p:---- s:0030 e:000029 CFUNC :loop<br>
c:0009 p:0007 s:0027 e:000026 BLOCK C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:2<br>
33 [FINISH]<br>
c:0008 p:---- s:0025 e:000024 CFUNC :catch<br>
c:0007 p:0015 s:0021 e:000020 METHOD C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:2<br>
32<br>
c:0006 p:0030 s:0018 E:000564 METHOD C:/Ruby200/lib/ruby/2.0.0/irb.rb:488<br>
c:0005 p:0008 s:0015 e:000014 BLOCK C:/Ruby200/lib/ruby/2.0.0/irb.rb:397 [FINIS<br>
H]<br>
c:0004 p:---- s:0013 e:000012 CFUNC :catch<br>
c:0003 p:0143 s:0009 E:0000d4 METHOD C:/Ruby200/lib/ruby/2.0.0/irb.rb:396<br>
c:0002 p:0031 s:0004 E:001d0c EVAL C:/Ruby200/bin/irb:12 [FINISH]<br>
c:0001 p:0000 s:0002 E:0023dc TOP [FINISH]</p>
<p>C:/Ruby200/bin/irb:12:in <code><main>' C:/Ruby200/lib/ruby/2.0.0/irb.rb:396:in </code>start'<br>
C:/Ruby200/lib/ruby/2.0.0/irb.rb:396:in <code>catch' C:/Ruby200/lib/ruby/2.0.0/irb.rb:397:in </code>block in start'<br>
C:/Ruby200/lib/ruby/2.0.0/irb.rb:488:in <code>eval_input' C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in </code>each_top_level_statement'<br>
C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in <code>catch' C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in </code>block in each_top_level_statem<br>
ent'<br>
C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in <code>loop' C:/Ruby200/lib/ruby/2.0.0/irb/ruby-lex.rb:247:in </code>block (2 levels) in each_top_l<br>
evel_statement'<br>
C:/Ruby200/lib/ruby/2.0.0/irb.rb:489:in <code>block in eval_input' C:/Ruby200/lib/ruby/2.0.0/irb.rb:624:in </code>signal_status'<br>
C:/Ruby200/lib/ruby/2.0.0/irb.rb:492:in <code>block (2 levels) in eval_input' C:/Ruby200/lib/ruby/2.0.0/irb/context.rb:380:in </code>evaluate'<br>
C:/Ruby200/lib/ruby/2.0.0/irb/workspace.rb:86:in <code>evaluate' C:/Ruby200/lib/ruby/2.0.0/irb/workspace.rb:86:in </code>eval'<br>
(irb):4:in <code>irb_binding' (irb):4:in </code>tell'</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394872013-05-22T22:11:34Zluislavena (Luis Lavena)luislavena@gmail.com
<ul><li><strong>Assignee</strong> changed from <i>nagachika (Tomoyuki Chikanaga)</i> to <i>nobu (Nobuyoshi Nakada)</i></li><li><strong>% Done</strong> changed from <i>100</i> to <i>50</i></li></ul><p>nobu-san, do you want me to commit the missing fix?</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394962013-05-23T11:15:20Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Backport</i> to <i>Bug</i></li><li><strong>Project</strong> changed from <i>Backport200</i> to <i>Ruby master</i></li><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Open</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394972013-05-23T11:17:34Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>platform/windows</i></li><li><strong>ruby -v</strong> set to <i>2.1.0</i></li></ul><p>Oops, [Backport] ticket can't catch the commit on trunk?<br>
I added the test for write at r80894 now.</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394982013-05-23T11:18:16Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>% Done</strong> changed from <i>50</i> to <i>100</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=394992013-05-23T11:18:32Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Backport</strong> set to <i>1.9.3: REQUIRED, 2.0.0: REQUIRED</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=395002013-05-23T11:19:03Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Backport</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>Backport200</i></li><li><strong>Category</strong> deleted (<del><i>platform/windows</i></del>)</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> changed from <i>nobu (Nobuyoshi Nakada)</i> to <i>nagachika (Tomoyuki Chikanaga)</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=395012013-05-23T11:21:40Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Calls to SetFilePointer() are extracted as a new function at r40887, and r40888 fixed it.</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=395032013-05-23T11:57:44Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Backport</i> to <i>Bug</i></li><li><strong>Project</strong> changed from <i>Backport200</i> to <i>Ruby master</i></li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=395042013-05-23T12:03:19Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>platform/windows</i></li><li><strong>Backport</strong> set to <i>1.9.3: REQUIRED, 2.0.0: REQUIRED</i></li><li><strong>ruby -v</strong> set to <i>2.1.0</i></li></ul><p>r40896 is needed too.</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=395052013-05-23T12:03:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Backport</i></li><li><strong>Project</strong> changed from <i>Ruby master</i> to <i>Backport200</i></li><li><strong>Category</strong> deleted (<del><i>platform/windows</i></del>)</li></ul> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=396742013-06-04T00:49:10Znagachika (Tomoyuki Chikanaga)nagachika00@gmail.com
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>This issue was solved with changeset r41056.<br>
Oleg, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>merge revision(s) 40887,40888,40894,40896: [Backport <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: File.read() crash on Win32SP3 32bit (Closed)" href="https://bugs.ruby-lang.org/issues/8431">#8431</a>]</p>
<pre><code>* win32/win32.c (setup_overlapped, finish_overlapped): extract from
rb_w32_read() and rb_w32_write().
* win32/win32.c (setup_overlapped): check the error code in addition
to the result of SetFilePointer() to determine if an error occurred,
because INVALID_SET_FILE_POINTER is a valid value.
<a href="/issues/8431">[ruby-core:55098]</a> [Bug #8431]
</code></pre> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=396752013-06-04T00:50:21Znagachika (Tomoyuki Chikanaga)nagachika00@gmail.com
<ul><li><strong>Project</strong> changed from <i>Backport200</i> to <i>Backport193</i></li><li><strong>Status</strong> changed from <i>Closed</i> to <i>Assigned</i></li><li><strong>Assignee</strong> changed from <i>nagachika (Tomoyuki Chikanaga)</i> to <i>usa (Usaku NAKAMURA)</i></li></ul><p>backport for 1.9.3 is also required?</p> Backport193 - Backport #8431: File.read() crash on Win32SP3 32bithttps://bugs.ruby-lang.org/issues/8431?journal_id=397142013-06-05T12:38:37Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>This issue was solved with changeset r41082.<br>
Oleg, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>merge revision(s) 40887,40888,40894,40896: [Backport <a class="issue tracker-4 status-5 priority-4 priority-default closed" title="Backport: File.read() crash on Win32SP3 32bit (Closed)" href="https://bugs.ruby-lang.org/issues/8431">#8431</a>]</p>
<pre><code>* win32/win32.c (setup_overlapped, finish_overlapped): extract from
rb_w32_read() and rb_w32_write().
* win32/win32.c (setup_overlapped): check the error code in addition
to the result of SetFilePointer() to determine if an error occurred,
because INVALID_SET_FILE_POINTER is a valid value.
<a href="/issues/8431">[ruby-core:55098]</a> [Bug #8431]
</code></pre>