with an SSH2 stream, fseek with fgets will yield unpredictable results
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
php-ssh2 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
When using fseek on an SSH2 stream, I will get unpredictable results.
The following sequence will fail :
- fopen text file on SSH2 stream
- fread 20 bytes
- fseek TO THE BEGINNING
- fgets /*should read first line but does not; instead reading half of Line 211 */
Removing the initial fread() will not cause the issue.
Also using fclose()/fopen() after the fread() will return the pointer to the beginning as well - but that is not a good workaround.
I was only able to reproduce it on 12.04.
The sample code ATTACHED will work properly on 14.04 or even 10.10.
You will need to edit the constants at the beginning of the file to match your SSH server username and password. Also you need to drop the test file on that server.
CORRECT OUTPUT ON 14.04:
administrator@
Starting tests...
Position: 0
Read...
Read bytes: Line 1
Line 2
Lin
Fseek...
Position: 0
*** NOTE: OUTPUT BELOW IS CORRECT ***
line 1: Line 1
line 2: Line 2
line 3: Line 3
Tests done
administrator@
DISTRIB_ID=Ubuntu
DISTRIB_
DISTRIB_
DISTRIB_
INCORRECT OUTPUT ON 12.04:
administrator@
Starting tests...
Position: 0
Read...
Read bytes: Line 1
Line 2
Lin
Fseek...
Position: 0
*** NOTE: OUTPUT IS INCORRECT HERE ***
line 1: 1
line 2: Line 212
line 3: Line 213
Tests done
administrator@
DISTRIB_ID=Ubuntu
DISTRIB_
DISTRIB_
DISTRIB_
ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: libssh2-php 0.11.2-1
ProcVersionSign
Uname: Linux 3.2.0-70-generic x86_64
ApportVersion: 2.0.1-0ubuntu17.8
Architecture: amd64
Date: Wed Feb 11 11:16:47 2015
InstallationMedia: Ubuntu-Server 12.04.1 LTS "Precise Pangolin" - Release amd64 (20120817.3)
MarkForUpload: True
ProcEnviron:
LANGUAGE=en_CA:en
TERM=xterm
PATH=(custom, no user)
LANG=en_CA.UTF-8
SHELL=/bin/bash
SourcePackage: php-ssh2
UpgradeStatus: No upgrade log present (probably fresh install)