Bug 29627 - [4.1 only] partial unformatted reads shouldn't succeed
Summary: [4.1 only] partial unformatted reads shouldn't succeed
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords: wrong-code
Depends on:
Blocks: 29568
  Show dependency treegraph
 
Reported: 2006-10-28 18:10 UTC by Thomas Koenig
Modified: 2006-11-04 14:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0 4.2.0
Known to fail: 4.1.2
Last reconfirmed: 2006-10-28 19:30:27


Attachments
preliminary patch (1.48 KB, patch)
2006-10-28 21:24 UTC, Thomas Koenig
Details | Diff
updated patch (1.49 KB, patch)
2006-10-29 11:49 UTC, Thomas Koenig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2006-10-28 18:10:21 UTC
$ cat partial.f90
program main
  character(len=1) a(2)
  open(10, form="unformatted",status="unknown")
  write (10) 'a'
  rewind 10
  a = 'b'
  read (10) a
  print *,a
end program main
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../../gcc/trunk/configure --prefix=/home/ig25 --enable-languages=c,fortran
Thread model: posix
gcc version 4.2.0 20061020 (experimental)

This should generate a runtime error. ifort gets this right:

$ ifort partial.f90
$ ./a.out
forrtl: severe (67): input statement requires too much data, unit 10, file /home/ig25/Krempel/Transfer/fort.10
Image              PC        Routine            Line        Source
a.out              08085958  Unknown               Unknown  Unknown
a.out              08085450  Unknown               Unknown  Unknown
a.out              08084A0D  Unknown               Unknown  Unknown
a.out              080648C8  Unknown               Unknown  Unknown
a.out              08064D6B  Unknown               Unknown  Unknown
a.out              08055937  Unknown               Unknown  Unknown
a.out              080554B1  Unknown               Unknown  Unknown
a.out              0804A239  Unknown               Unknown  Unknown
a.out              0804A13C  Unknown               Unknown  Unknown
Unknown            A7E40EA8  Unknown               Unknown  Unknown
a.out              08049FF1  Unknown               Unknown  Unknown
Comment 1 Thomas Koenig 2006-10-28 18:11:40 UTC
Uh, I forgot the actual output from the program:

$ gfortran partial.f90
$ ./a.out
 ab
Comment 2 Thomas Koenig 2006-10-28 21:24:36 UTC
Created attachment 12504 [details]
preliminary patch
Comment 3 Jerry DeLisle 2006-10-28 23:21:07 UTC
I had considered flipping the logic around on is_stream_io as you have done in the  preliminary patch.  The first versions of stream_io I was leaving the existing code completely untouched while testing out the overall approach.  Now that we are in 4.3 this is a good time to do some cleanup.  Overall, the prelminary patch approach looks good, but I have not tested yet.
Comment 4 Thomas Koenig 2006-10-29 11:49:26 UTC
Created attachment 12506 [details]
updated patch

In the previous patch, I had ommitted one test too many
(the one for EOF).  Here's an updated version.
Comment 5 Thomas Koenig 2006-10-29 11:59:16 UTC
(In reply to comment #3)

Hi Jerry,

> Now
> that we are in 4.3 this is a good time to do some cleanup.  Overall, the
> prelminary patch approach looks good, but I have not tested yet.

There's another reason why I want the cleanup: For implementing Intel
record markers (PR 29568).  Interleaving stream and record I/O would
lead to so many if statements that I'd never get this right :-)

Thomas


Comment 6 Thomas Koenig 2006-10-31 20:58:38 UTC
Subject: Bug 29627

Author: tkoenig
Date: Tue Oct 31 20:58:26 2006
New Revision: 118341

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118341
Log:
2006-10-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	* libgfortran.h: Add ERROR_SHORT_RECORD
	* runtime/error.c (translate_error): Add case
	for ERROR_SHORT_RECORD.
	* io/transfer.c (read_block_direct):  Separate codepaths
	for stream and record unformatted I/O.  Remove unneeded
	tests for standard input, padding and formatted I/O.
	If the record is short, read in as much data as possible,
	then raise the error.

2006-10-31  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	* gfortran.dg/unf_short_record_1.f90:  New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/unf_short_record_1.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/libgfortran.h
    trunk/libgfortran/runtime/error.c

Comment 7 Thomas Koenig 2006-11-01 10:17:11 UTC
Fixed on trunk.
Comment 8 Thomas Koenig 2006-11-03 11:22:42 UTC
Subject: Bug 29627

Author: tkoenig
Date: Fri Nov  3 11:22:27 2006
New Revision: 118453

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118453
Log:
2006-11-03  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	Backport from trunk
	* libgfortran.h: Add ERROR_SHORT_RECORD
	* runtime/error.c (translate_error): Add case
	for ERROR_SHORT_RECORD.
	* io/transfer.c (read_block_direct):  Separate codepaths
	for stream and record unformatted I/O.  Remove unneeded
	tests for standard input, padding and formatted I/O.
	If the record is short, read in as much data as possible,
	then raise the error.

2006-11-03  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	Backport from trunk
	* gfortran.dg/unf_short_record_1.f90:  New test.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/unf_short_record_1.f90
Modified:
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/libgfortran/ChangeLog
    branches/gcc-4_2-branch/libgfortran/io/transfer.c
    branches/gcc-4_2-branch/libgfortran/libgfortran.h
    branches/gcc-4_2-branch/libgfortran/runtime/error.c

Comment 9 Thomas Koenig 2006-11-03 11:30:32 UTC
Fixed on 4.2 too; will need to regtest for backporting
to 4.1.
Comment 10 Thomas Koenig 2006-11-04 14:04:38 UTC
Subject: Bug 29627

Author: tkoenig
Date: Sat Nov  4 14:04:27 2006
New Revision: 118480

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118480
Log:
2006-11-04  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	Backport from trunk
	* libgfortran.h: Add ERROR_SHORT_RECORD
	* runtime/error.c (translate_error): Add case
	for ERROR_SHORT_RECORD.
	* io/transfer.c (read_block_direct):  Remove unneeded
	tests for standard input, padding and formatted I/O.
	If the record is short, read in as much data as possible,
	then raise the error.

2006-11-04  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/29627
	Backport from trunk
	* gfortran.dg/unf_short_record_1.f90:  New test.


Added:
    branches/gcc-4_1-branch/gcc/testsuite/gfortran.dg/unf_short_record_1.f90
Modified:
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/libgfortran/ChangeLog
    branches/gcc-4_1-branch/libgfortran/io/transfer.c
    branches/gcc-4_1-branch/libgfortran/libgfortran.h
    branches/gcc-4_1-branch/libgfortran/runtime/error.c

Comment 11 Thomas Koenig 2006-11-04 14:05:28 UTC
Fixed on 4.1 as well, after regression-testing.

Closing.