public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays
@ 2021-12-09 18:00 anlauf at gcc dot gnu.org
  2021-12-09 18:27 ` [Bug libfortran/103634] " anlauf at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-09 18:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

            Bug ID: 103634
           Summary: Runtime crash with PACK on zero-sized arrays
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

I thought we had fixed this one (see PR31001), but maybe not completely:

program p
  implicit none
  type t
     real :: r(24) = -99.
  end type
  type(t), allocatable :: new(:), old(:)
  logical, allocatable :: mask(:)
  integer              :: n, m
! m = 1    ! works
  m = 0    ! fails
  allocate (old(m), mask(m))
  mask(:) = .false.
  n = count (mask)
  allocate (new(n))
  new(:) = pack (old, mask)
  print *, size (new)
end

% ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x151ef209949f in ???
#1  0x151ef2e263e0 in pack_internal
        at ../../../gcc-trunk/libgfortran/intrinsics/pack_generic.c:182
#2  0x401194 in p
        at /home/anlauf/gcc-bugs/pack-bug.f90:15
#3  0x401255 in main
        at /home/anlauf/gcc-bugs/pack-bug.f90:17

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
@ 2021-12-09 18:27 ` anlauf at gcc dot gnu.org
  2021-12-09 20:06 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-09 18:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran
   Last reconfirmed|                            |2021-12-09
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
Untested fix:

diff --git a/libgfortran/intrinsics/pack_generic.c
b/libgfortran/intrinsics/pack_generic.c
index cad2fbbfbcd..f629e0e8469 100644
--- a/libgfortran/intrinsics/pack_generic.c
+++ b/libgfortran/intrinsics/pack_generic.c
@@ -126,6 +126,10 @@ pack_internal (gfc_array_char *ret, const gfc_array_char
*array,
   if (mstride[0] == 0)
     mstride[0] = mask_kind;

+  for (n = 0; n < dim; n++)
+    if (extent[n] == 0)
+      return;
+
   if (ret->base_addr == NULL || unlikely (compile_options.bounds_check))
     {
       /* Count the elements, either for allocating memory or

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
  2021-12-09 18:27 ` [Bug libfortran/103634] " anlauf at gcc dot gnu.org
@ 2021-12-09 20:06 ` anlauf at gcc dot gnu.org
  2021-12-14 15:57 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-09 20:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2021-December/057149.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
  2021-12-09 18:27 ` [Bug libfortran/103634] " anlauf at gcc dot gnu.org
  2021-12-09 20:06 ` anlauf at gcc dot gnu.org
@ 2021-12-14 15:57 ` cvs-commit at gcc dot gnu.org
  2021-12-19 20:14 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-14 15:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:1c613165a55b212c59a83796b20a1d555e096504

commit r12-5961-g1c613165a55b212c59a83796b20a1d555e096504
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Dec 13 20:50:19 2021 +0100

    Fortran: PACK intrinsic should not try to read from zero-sized array

    libgfortran/ChangeLog:

            PR libfortran/103634
            * intrinsics/pack_generic.c (pack_internal): Handle case when the
            array argument of PACK has one or more extents of size zero to
            avoid invalid reads.

    gcc/testsuite/ChangeLog:

            PR libfortran/103634
            * gfortran.dg/intrinsic_pack_6.f90: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-12-14 15:57 ` cvs-commit at gcc dot gnu.org
@ 2021-12-19 20:14 ` cvs-commit at gcc dot gnu.org
  2021-12-27 20:09 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-19 20:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:05640d5ca8a20929f30eef41baee3e4a8d85c898

commit r11-9403-g05640d5ca8a20929f30eef41baee3e4a8d85c898
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Dec 13 20:50:19 2021 +0100

    Fortran: PACK intrinsic should not try to read from zero-sized array

    libgfortran/ChangeLog:

            PR libfortran/103634
            * intrinsics/pack_generic.c (pack_internal): Handle case when the
            array argument of PACK has one or more extents of size zero to
            avoid invalid reads.

    gcc/testsuite/ChangeLog:

            PR libfortran/103634
            * gfortran.dg/intrinsic_pack_6.f90: New test.

    (cherry picked from commit 1c613165a55b212c59a83796b20a1d555e096504)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-12-19 20:14 ` cvs-commit at gcc dot gnu.org
@ 2021-12-27 20:09 ` cvs-commit at gcc dot gnu.org
  2021-12-27 20:13 ` cvs-commit at gcc dot gnu.org
  2021-12-27 20:14 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-27 20:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:39264acd7daaff4659fefa005ec02bccf685447d

commit r10-10363-g39264acd7daaff4659fefa005ec02bccf685447d
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Dec 13 20:50:19 2021 +0100

    Fortran: PACK intrinsic should not try to read from zero-sized array

    libgfortran/ChangeLog:

            PR libfortran/103634
            * intrinsics/pack_generic.c (pack_internal): Handle case when the
            array argument of PACK has one or more extents of size zero to
            avoid invalid reads.

    gcc/testsuite/ChangeLog:

            PR libfortran/103634
            * gfortran.dg/intrinsic_pack_6.f90: New test.

    (cherry picked from commit 1c613165a55b212c59a83796b20a1d555e096504)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-12-27 20:09 ` cvs-commit at gcc dot gnu.org
@ 2021-12-27 20:13 ` cvs-commit at gcc dot gnu.org
  2021-12-27 20:14 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-27 20:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:5b3587012951655d8e06dcfe683801862d3979de

commit r9-9889-g5b3587012951655d8e06dcfe683801862d3979de
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Dec 13 20:50:19 2021 +0100

    Fortran: PACK intrinsic should not try to read from zero-sized array

    libgfortran/ChangeLog:

            PR libfortran/103634
            * intrinsics/pack_generic.c (pack_internal): Handle case when the
            array argument of PACK has one or more extents of size zero to
            avoid invalid reads.

    gcc/testsuite/ChangeLog:

            PR libfortran/103634
            * gfortran.dg/intrinsic_pack_6.f90: New test.

    (cherry picked from commit 1c613165a55b212c59a83796b20a1d555e096504)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libfortran/103634] Runtime crash with PACK on zero-sized arrays
  2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-12-27 20:13 ` cvs-commit at gcc dot gnu.org
@ 2021-12-27 20:14 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-27 20:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103634

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |9.5

--- Comment #7 from anlauf at gcc dot gnu.org ---
Fixed on all open branches.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-27 20:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 18:00 [Bug fortran/103634] New: Runtime crash with PACK on zero-sized arrays anlauf at gcc dot gnu.org
2021-12-09 18:27 ` [Bug libfortran/103634] " anlauf at gcc dot gnu.org
2021-12-09 20:06 ` anlauf at gcc dot gnu.org
2021-12-14 15:57 ` cvs-commit at gcc dot gnu.org
2021-12-19 20:14 ` cvs-commit at gcc dot gnu.org
2021-12-27 20:09 ` cvs-commit at gcc dot gnu.org
2021-12-27 20:13 ` cvs-commit at gcc dot gnu.org
2021-12-27 20:14 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).