The PHPdoc for stream_seek() says:

  /**
   * Support for fseek().
   *
   * @param $offset
   *   The byte offset to got to.
   * @param $whence
   *   SEEK_SET, SEEK_CUR, or SEEK_END.
   *
   * @return
   *   TRUE on success.
   *
   * @see http://php.net/manual/en/streamwrapper.stream-seek.php
   */

and the current implementation of stream_seek() returns the result of a fseek() call, which is documented as having a different return value on http://www.php.net/manual/en/function.fseek.php:

fseek()
Return Values:
Upon success, returns 0; otherwise, returns -1. Note that seeking past EOF is not considered an error.

So, for success, stream_seek() should return TRUE but fseek() returns 0.

The bug is noticeable when the image API calls getimagesize() for a .jpg image that has some EXIF metadata that it has to skip over (using fseek())

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

asimmonds’s picture

Status: Active » Needs review

Looks like dir_rewinddir() and dir_closedir() could have similar problems, their equivalent non-stream functions both return void instead of a boolean.

Damien Tournoud’s picture

Just for the record: PHP--

chx’s picture

FileSize
1.4 KB

We need a test for this.

chx’s picture

AaronBauman’s picture

Dries’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I committed #3 but marking it as 'needs work' because we want tests.

asimmonds’s picture

Status: Needs work » Needs review
FileSize
4.44 KB

First try at some stream_wrappers.inc tests.
- Should these be true unit tests testing the class methods, or abstracted through the PHP filesystem functions like I've done here?

Damien Tournoud’s picture

My guess would be that we can probably reuse some tests from PHP itself here. What we want is general tests for a stream-wrapper implementation, that can be easily reused by contrib.

andypost’s picture

Great start, suppose this needs more extended tests to catch bugs like file_uri_target() pointed in #278425-35: Using basename() is not locale safe

marcingy’s picture

Priority: Normal » Major

Changing to major as per tag.

MustangGB’s picture

Tag update

sun.core’s picture

Priority: Major » Normal

All that remains here are tests, and we'll always miss some tests - not major.

skyredwang’s picture

Status: Needs review » Closed (fixed)

This patch was committed by someone. Mark fixed.

skyredwang’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Needs work

#3 patch is committed, but it doesn't solve the problem.

lotyrin’s picture

Priority: Critical » Normal

This was normal (major at the highest, never critical), and unless I'm mistaken is just needing tests.

Tor Arne Thune’s picture

Title: Stream wrappers stream_seek() return is invalid » (Tests needed) Stream wrappers stream_seek() return is invalid
Version: 7.x-dev » 8.x-dev
Category: bug » task
Issue tags: +Needs backport to D7
chx’s picture

Guys, #3 applies to D7. Requests for a backport are deleted.

andypost’s picture

#3 already in 7 & 8 so only tests #7 should be backported

tac11tac’s picture

Version: 8.x-dev » 7.9
Component: file system » image system
Category: task » bug

Newbie here... This issue is still showing in v7.9 when uploading .jpg images. #16 says a backport to v7 is needed, and #19 says that the commit in #3 was for the v7 branch. However, #3 looks like it only hit the v8 branch. Could someone validate this and hopefully patch v7 for the next release? Thanks.

lotyrin’s picture

Version: 7.9 » 8.x-dev

Fixing version.

The comment in #21 shouldn't be ignored however.

lotyrin’s picture

Component: image system » file system
Category: bug » task

Reverting other changes from #21

andypost’s picture

Status: Needs work » Needs review
FileSize
4.16 KB

Re-roll of tests

PS: @tac11tac and others - #3 has been commited a long ago! check the code base

Status: Needs review » Needs work

The last submitted patch, 844676-streams_tests.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
4.17 KB

Re-roll with p1 and fixed remains of $Id$

thedavidmeister’s picture

Status: Needs review » Needs work

patch no longer applies, simpletest.info does not exist.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 57ab633 on 8.3.x
    - Patch #844676 by chx, asimmonds: stream wrappers stream_seek() return...

  • Dries committed 57ab633 on 8.3.x
    - Patch #844676 by chx, asimmonds: stream wrappers stream_seek() return...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • Dries committed 57ab633 on 8.4.x
    - Patch #844676 by chx, asimmonds: stream wrappers stream_seek() return...

  • Dries committed 57ab633 on 8.4.x
    - Patch #844676 by chx, asimmonds: stream wrappers stream_seek() return...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

  • Dries committed 57ab633 on 9.1.x
    - Patch #844676 by chx, asimmonds: stream wrappers stream_seek() return...

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.