[ruby-core:102755] [Ruby master Bug#17673] sysseek(0) and '1A' in header return "EOFError (end of file reached)"
From:
merch-redmine@...
Date:
2021-03-05 23:46:28 UTC
List:
ruby-core #102755
Issue #17673 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Feedback to Closed
I tried on Windows and I was able to reproduce the issue:
```
C:\Users\jeremye>c:\Ruby30-x64\bin\ruby
filePath = 'test.txt'
File.binwrite(filePath, "\x1A\x45")
descriptor = IO.sysopen(filePath)
file2Read = IO.new(descriptor)
file2Read.sysseek(0)
p file2Read.sysread(2).unpack('H*')
__END__
-:7:in `sysread': end of file reached (EOFError)
from -:7:in `<main>'
```
From some brief research, this is expected behavior on Windows for text files. You need to put the file in binary mode (IO#binmode):
```
:\Users\jeremye>c:\Ruby30-x64\bin\ruby
filePath = 'test.txt'
File.binwrite(filePath, "\x1A\x45")
descriptor = IO.sysopen(filePath)
file2Read = IO.new(descriptor)
file2Read.binmode
file2Read.sysseek(0)
p file2Read.sysread(2).unpack('H*')
__END__
["1a45"]
```
----------------------------------------
Bug #17673: sysseek(0) and '1A' in header return "EOFError (end of file reached)"
https://bugs.ruby-lang.org/issues/17673#change-90768
* Author: stiuna (Juan Gregorio)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
The first byte of my file starts with the value **'1A'** .
Then:
``` ruby
descriptor = IO.sysopen(filePath)
file2Read = IO.new(descriptor)
file2Read.sysseek(0)
p file2Read.sysread(2).unpack('H*')
#=> "EOFError (end of file reached)"
```
But when I change the first byte of my file to **'AA'** for example.
Then:
``` ruby
#=> "aa45"
```
Is it a bug or am I missing something? I thought sysseek only changed the cursor and nothing else.
This error only occurs with byte **'1A'** I did the test with the rest of the bytes **[00..FF]** and there is no problem except with **'1A'** .
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>