jgigault / 42FileChecker

42FileChecker is a tiny bash script developed at 42 school for testing and checking files according to the rules of the subjects
Apache License 2.0
306 stars 56 forks source link

Get next line - very large fd #129

Open KalindiFonda opened 5 years ago

KalindiFonda commented 5 years ago

if one implements gnl by using a mx_fd option, a very large fd causes a seg fault.

jgigault commented 5 years ago

Hello @KalindiFonda Can you please provide me an example of that implementation?

KalindiFonda commented 5 years ago

Hi, my code failed when moulinette used a very large fd, and that is because of the way I set my static variable - as it depends on a number (MAX_FD_N) I give it. static char *r_str[MAX_FD_N];

Would it be useful for you to see my code?

jgigault commented 5 years ago

Yes, for sure I am interested in look at your code. It would be nice if you provide me a full example of the issue: a large file and your main.c?

tobyhw commented 5 years ago

The issue here is not a large file but a large fd.

I have seen implementations like this where essentially a large array of string pointers is initiated as a static variable and accessed simply using r_str[fd] when called.

The problem is that if too many files are open, the fd may be greater than MAX_FD_N. If this value is large enough, you will not have an error (which should be a bus error and not a segfault), but then you're using about 80MB of memory for no reason. It would be interesting to add this test as I have seen a lot of implementations lately that take this (highly inefficient) shortcut

jgigault commented 4 years ago

Hello @tobyhw How would you handle tests for that issue? Should we open file descriptors with gnl with huge number of iterations? How many iterations? How to determine when the test is relevant?