Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems when reading special procfs file #25596

Closed
hexchain opened this issue Jan 27, 2016 · 2 comments
Closed

Problems when reading special procfs file #25596

hexchain opened this issue Jan 27, 2016 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io

Comments

@hexchain
Copy link

OS: 4.4.0-4-ARCH

Reading special procfs file (e.g. /proc/$PID/smaps) as chunk does not always return a full chunk before reaching EOF.

Currently Dart determines EOF by trying to read BLOCK_SIZE of bytes and checking if the length of returned bytes equals to BLOCK_SIZE, which may fail in such special circumstances. Relevant code is here and here, maybe more.

And here's a simple test in C:

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

#define BLOCK_SIZE 64 * 1024

int main(void)
{
    int fd = open("/proc/918/smaps", O_RDONLY); // change the PID part accordingly
    int r = 0, t = 0;
    char buf[BLOCK_SIZE];
    do {
        r = read(fd, buf, BLOCK_SIZE);
        t += r;
        printf("r = %d\n", r); // r is not always BLOCK_SIZE
    } while(r > 0);  // Notice this expression
    printf("t = %d\n", t);
    return 0;
}
@rmacnak-google rmacnak-google added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io labels Jan 30, 2016
@sgjesse sgjesse self-assigned this Feb 1, 2016
@sgjesse
Copy link
Contributor

sgjesse commented Feb 1, 2016

Thanks for the report. Proposed fix in https://codereview.chromium.org/1651023003.

@sgjesse
Copy link
Contributor

sgjesse commented Feb 10, 2016

Will be released in 1.14.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-io
Projects
None yet
Development

No branches or pull requests

3 participants