Exploit using files in HW4 (to get extremely low efficiency)

gianluca5539 (9820 points)
3 6 44
asked Nov 12, 2021 in HW4 by gianluca5539 (9,820 points)
Yesterday I noticed that you can score a very very good efficiency, as little as 30ms, by exploiting a "bug" in the VM test system.

This is what i think happens:

Since the tests are repeated, you can make the code execute almost instantly in all test rounds after the first by opening the files with mode 'x', exclusive creating mode.

As the files already exist after the first test, the exclusive creating mode will throw an error saying that the file already exists. This will take an extremely small amount of time and so the total execution time will be very small. The result is then all tests passed in ~35ms.

This is obviously not a fair way to solve the homework.

The "fix" is easy: just use the 'w' mode, which will create the files if they don't exist or overwrite them if they exist.

I'm writing this so that, if you find a very small execution time, you know that you are actually (probably without even noticing) exploiting a bug.

Wish everyone good luck with HW4!
259 views

3 Answers

andrea.sterbini (172340 points)
510 927 1776
answered Nov 12, 2021 by andrea.sterbini (172,340 points)
edited Nov 12, 2021 by andrea.sterbini
Thanks for signaling this, I've added an "file open mode check" to the VM tests
andrea.sterbini (172340 points)
510 927 1776
commented Nov 15, 2021 by andrea.sterbini (172,340 points)
Found an even easier solution: delete the output file after the test
James_F (4580 points)
7 14 36
answered Nov 12, 2021 by James_F (4,580 points)
Brilliant catch!
Quellocinese (2700 points)
2 4 22
answered Nov 12, 2021 by Quellocinese (2,700 points)
This is brilliant.