From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Tue Oct 12 11:34:59 2021
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Tue, 12 Oct 2021 11:34:59 +0200
Subject: [Rd] int overflow writing long vectors to socketConnection
In-Reply-To: <0E317F6A-E81C-47E5-9388-F14A8F392B87@gmail.com>
References: <0E317F6A-E81C-47E5-9388-F14A8F392B87@gmail.com>
Message-ID: <24933.22211.780123.250926@stat.math.ethz.ch>

>>>>> Zafer Barutcuoglu 
>>>>>     on Tue, 12 Oct 2021 02:04:40 -0400 writes:

    > Hi,

    > Writing >=2GB to a socketConnection (e.g. via writeBin) does not work correctly, because of this int typecast in modules/internet/sockconn.c:
    >> static size_t sock_write(const void *ptr, size_t size, size_t nitems,
    >> Rconnection con)
    >> {
    >> Rsockconn this = (Rsockconn)con->private;
    >> ssize_t n = R_SockWrite(this->fd, ptr, (int)(size * nitems),
    this-> timeout)/((ssize_t)size);
    >> return n > 0 ? n : 0;
    >> }
    > which seems uncalled for, given:
    >> ssize_t R_SockWrite(int sockp, const void *buf, size_t len, int timeout)


    > Is there a rationale for it, or should it be fixed?

I've fixed it; it's clearly been a  "typo" introduced at the
same when the type of 'len' in the R_SockWrite() header was
changed from int to size_t .. and the intent must have been to
do the same inside sock_write().

    > Best,
    > --
    > Zafer

Thank you for the report!

Martin Maechler
ETH Zurich  and  R Core



[Rd] int overflow writing long vectors to socketConnection
Martin Maechler