Errors caused by the machine with an EINVAL error

It has some long background in front of the actual question, however, it carries some explanations, to hopefully weed some red herrings.

Our application, developed in Microsoft Visual C ++ (2005), uses a third-party library (with the source code, which we, fortunately, we have), to export the compressed file used in another third-party application. The library is responsible for creating the exported file, managing data and compressing and, as a rule, handling all errors. Recently, we began to receive feedback that on some machines our application will crash while writing to a file. Based on some initial research, we were able to determine the following:

  • Accidents occurred on various hardware settings and operating systems (although our clients are limited to XP / 2000)
  • Accidents always happen on one data set; however, they will not be found in all data sets.
  • For a set of data that caused a crash, the accident cannot be reproduced on all machines even with the same characteristics, that is, with the operating system, the amount of RAM, etc.
  • The error will appear only when the application was launched in the installation directory - not when creating from Visual Studio, starting in debug mode, or even starting in other directories that the user had access to
  • The problem occurs if the file is created on a local or mapped drive.

, ( ):

 while (size>0) {
    do {
        nbytes = _write(file->fd, buf, size);
    } while (-1==nbytes && EINTR==errno);
    if (-1==nbytes) /* error */
        throw("file write failed")
    assert(nbytes>0);
    assert((size_t)nbytes<=size);
    size -= (size_t)nbytes;
    addr += (haddr_t)nbytes;
    buf = (const char*)buf + nbytes;
}

, _write 22 EINVAL. MSDN, _write return EINVAL , (buf ) . , , , .

- 250 , . , , , , . , , , / . , :

  • - , _write ? - _write - - Visual ++?
  • - , ( 250 , ) - - , , , ?

UPDATE: , :

  • , . , , ( )
  • , . , EINVAL , 0, buf , , .

:

printfs .

     while (size>0) {
    if (NULL == buf)
    {
        printf("Buffer is null\n");
    }
    do {
        nbytes = _write(file->fd, buf, size);
    } while (-1==nbytes && EINTR==errno);
    if (-1==nbytes) /* error */
    {
        if (NULL == buf)
        {
            printf("Buffer is null post write\n");
        }
        printf("Error number: %d\n", errno);
        printf("Buffer address: %d\n", &buf);
        printf("Size: %d\n", size);
        throw("file write failed")
    }
    assert(nbytes>0);
    assert((size_t)nbytes<=size);
    size -= (size_t)nbytes;
    addr += (haddr_t)nbytes;
    buf = (const char*)buf + nbytes;
}

:

Error number: 22
Buffer address: 1194824
Size: 89702400

, ( NULL , pre post _write)

, . (, , ) . 1. . , RAID (RAID 0 RAID 1) . RAID 0 ; RAID 1 . , ; - / - . 2. . , _write, 64 , . 32 , . , _write , , .

, ( Microsoft , ) , EINVAL . , , - - API- C.

- , , . , .

+3
5

, . :

#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{ int len = 70000000;
  int handle= creat(argv[1], S_IWRITE | S_IREAD);
  setmode (handle, _O_BINARY);
  void *buf = malloc(len);
  int byteswritten = write(handle, buf, len);
  if (byteswritten == len)
    printf("Write successful.\n");
  else
    printf("Write failed.\n");
  close(handle);
  return 0;
}

, mycomputer C:\inbox \\mycomputer\inbox. :

C:\>a.exe C:\inbox\x
Write successful.

C:\>a.exe \\mycomputer\inbox\x
Write failed.

, len 60000000, ...

- support.microsoft.com/kb/899149, , " " ( ). , 63 , . -, ​​ Windows Vista.

, !

+4

_write() CRT (C runtime), Visual Studio (C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\write.c)?

, _write() errno EINVAL:

  • buffer NULL, .
  • count , UTF-16 ( UTF-8? ). ? , ?
  • , , _write(), errno EINVAL?

, , , . , CRT , , ( , t ).

+1

http://msdn.microsoft.com/en-us/library/1570wh78(v=VS.90).aspx errno :

- EBADF
- ENOSPC
- EINVAL.

Windows EINTR. while (-1==nbytes && EINTR==errno);

+1

. , , . , , .

, 250 . .

, " ", , ?

, , ( ) ( ), ...

Kernel WriteFile(), ( NtWriteFile()), . , , , UM KM.

, , , ...

, . - " !", . ..

0

You can destroy your own stack by accidentally abusing the pointer somewhere else - if you can find the player, try running the application under Application Verifier with memory checks turned on

0
source

Source: https://habr.com/ru/post/1703787/


All Articles