[bug #68160] dlmread mishandle Inf

"Dmitri A. Sergatskov" <[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

URL:
  <https://savannah.gnu.org/bugs/?68160>

                 Summary: dlmread mishandle Inf
                   Group: GNU Octave
               Submitter: dasergatskov
               Submitted: Tue 17 Mar 2026 05:39:32 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Unexpected Error or Warning
                  Status: None
             Assigned to: None
         Originator Name:
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: dev
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 17 Mar 2026 05:39:32 PM UTC By: Dmitri A. Sergatskov <dasergatskov>
Trying to read attached (file test3.dat) with "dlmread" with octave compiled
with UBSAN:

octave:2> C= dlmread("test3.dat", ',', [2,0,inf,inf], "emptyvalue", NaN)
../libinterp/corefcn/dlmread.cc:161:43: runtime error: 9.22337e+18 is outside
the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../libinterp/corefcn/dlmread.cc:161:43 
../libinterp/corefcn/dlmread.cc:162:43: runtime error: 9.22337e+18 is outside
the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../libinterp/corefcn/dlmread.cc:162:43 
C = [](0x0)

(w/o UBSAN it just returns [] which is also wrong). 
The code works if I use just a large number instead of Inf

octave:3> C= dlmread("test3.dat", ',', [2,0,1e6,1e6], "emptyvalue", NaN)
C =

  100000.0000  100100.0000   0.0980   5.5500  85.0000
  1000000.0000  1005000.0000   0.0180   5.7500      NaN
  10000.0000  10050.0000   0.8900   5.5500  80.0000
  1000.0000  997.0000   4.7400   5.5500  31.0000
  100.0000  100.5000   5.5100   5.5500   3.5000
  10.0000  10.0000   5.5100   5.5500   0.3000
   1.0000   1.1810   5.5100   5.5500   0.6000


The issue is with the code:

157 
158       // double --> unsigned int avoiding any overflow
159       rlo = static_cast<octave_idx_type> (std::min (range(0),
idx_max_dbl));
160       clo = static_cast<octave_idx_type> (std::min (range(1),
idx_max_dbl));
161       rup = static_cast<octave_idx_type> (std::min (range(2),
idx_max_dbl));
162       cup = static_cast<octave_idx_type> (std::min (range(3),
idx_max_dbl));
163     }

("octave_idx_type" is signed, so the comment is also wrong)
I will look into it, and should be able to make a CSET later today...

Dmitri.
--






    _______________________________________________________
File Attachments:

Name: test3.dat                      Size: 392B
    <https://file.savannah.gnu.org/file/test3.dat?file_id=58370>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-eea52b5e705aceab0b59a30a7e37b2d35bfc1c3a.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68160>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCabmR2gAKCRCqLAuaBUf3
Tg96AP9vh7SO3qwE5JgNe3gVS73pPqJC8fO5qZd+VkfkQsWfqAD/TTtz2eIGGhMg
ODqnYqFjiAzpWgyoXST9FPAXmv9caAA=
=UoEW
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.