Bug 576929 - perl -i ignores write errors: results in silent data loss
Summary: perl -i ignores write errors: results in silent data loss
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: perl
Version: 24
Hardware: All
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jitka Plesnikova
QA Contact: Fedora Extras Quality Assurance
URL: http://rt.perl.org/rt3//Public/Bug/Di...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-03-25 16:24 UTC by Jim Meyering
Modified: 2017-07-26 08:31 UTC (History)
11 users (show)

Fixed In Version: perl-5.26.0-392.fc27
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-07-26 08:31:47 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jim Meyering 2010-03-25 16:24:11 UTC
Description of problem:
perl -i is very handy.  It allows me to filter a file and replace it with the result.  I can even use the -i.bak option to make a backup.
However, if while writing the new version (with or without .bak) perl encounters a write error, it silently ignores it and destroys the original file regardless of the fact that the "filtered" replacement is incomplete.
Even if I use .bak, and hence create a backup of the original, perl's failure makes it appear that the filtering process has completed normally, and the unsuspecting user may well remove the backup file.

Version-Release number of selected component (if applicable): perl-5.10.0-87.fc12.x86_64

How reproducible: always (with a nearly-full partition)

I've just done the following on a nearly-full partition:

Start off with a two-byte file:

    $ echo b > j

Use "perl -i" to filter that "in-place", increasing its size:

    $ perl -ni -e '/b/ and print "."x100000 . "\nlast\n"' j \
      && echo 'success, supposedly'
    success, supposedly

Perl didn't report any problem and has exited successfully.
Sounds good.  But.
Check out the size of the result:

    $ wc -c j
    65536 j

That certainly looks wrong.  65536 (aka 64KiB) < 100000 + 6.
We should see that final "last" line.

    $ tail -c 10 j; echo
    ..........

Confirmed.  Truncated file, and write failure not reported.

The above was done both with Fedora 12's v5.10.0
and with blead (built minutes ago, v5.12.0-RC0-6-gd419ab1).
Rerunning with "strace -e write perl ..., I see this:

    write(4, "................................"..., 4096) = 4096
    ...(15 others, identical)...
    write(4, "................................"..., 4096) = -1 ENOSPC (No space left on device)
    ...(7 others, identical)...
    write(4, "................................"..., 1702) = -1 ENOSPC (No space left on device)

Steps to Reproduce: as above
  
Actual results: as above

Expected results: perl reports the failure and does not destroy the input

Comment 1 Jim Meyering 2010-03-25 17:02:25 UTC
Since this can result in data loss, I've raised severity to "high"

Comment 2 Marcela Mašláňová 2010-03-26 09:06:45 UTC
I created upstream ticket.

Comment 3 Bug Zapper 2010-11-03 18:38:07 UTC
This message is a reminder that Fedora 12 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 12.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '12'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 12's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 12 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 4 Jim Meyering 2010-11-03 19:17:06 UTC
I've just reproduced the above failure on rawhide, using
perl-5.10.1-120.fc13.x86_64

Comment 6 Fedora End Of Life 2013-04-03 19:55:23 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19

Comment 7 Fedora Admin XMLRPC Client 2013-08-12 11:49:29 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 8 Fedora End Of Life 2015-01-09 21:43:02 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 9 Jim Meyering 2015-01-18 04:57:57 UTC
I have confirmed that this still affects rawhide (22-to-be).

Comment 10 Fedora End Of Life 2015-11-04 15:43:11 UTC
This message is a reminder that Fedora 21 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 21. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '21'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 21 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 11 Petr Pisar 2016-03-07 14:44:27 UTC
A related new upstream bug report <https://rt.perl.org/Public/Bug/Display.html?id=127663>.

Comment 12 Fedora End Of Life 2016-07-19 20:24:35 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.

Comment 13 Fedora End Of Life 2016-11-24 10:27:10 UTC
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '23'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 23 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 14 Fedora End Of Life 2017-07-25 18:28:13 UTC
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 15 Petr Pisar 2017-07-26 08:31:47 UTC
Perl 5.26.0 brought some improvements. In your use case, it recognizes failed write(2) and report it on the stderr and returns a non-zero exit code. The only drawback is the original file content is lost:

# echo a > /mnt/t/j
# perl -ni -e '/a/ and print "."x20000000 . "\nlast\n"' /mnt/t/j && echo 'success, supposedly'
Failed to close in-place edit file /mnt/t/j: No space left on device
# ls -l /mnt/t/j 
-rw-r--r--. 1 root root 1028096 Jul 26 10:27 /mnt/t/j
# tail -c 10 /mnt/t/j; echo
..........

I think I can close this bug report. Unfortunately it's impossible to port the change back to older perls because it's very intrusive.


Note You need to log in before you can comment on or make changes to this bug.