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

Comments

@hexchain
Copy link

commented Jan 27, 2016

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;
}
@sgjesse

This comment has been minimized.

Copy link
Member

commented Feb 1, 2016

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

@sgjesse

This comment has been minimized.

Copy link
Member

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
Projects
None yet
3 participants
You can’t perform that action at this time.