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

static array size過大可能導致DoS #7

Open
jaidTw opened this issue May 2, 2018 · 3 comments
Open

static array size過大可能導致DoS #7

jaidTw opened this issue May 2, 2018 · 3 comments

Comments

@jaidTw
Copy link

jaidTw commented May 2, 2018

近期在師大這邊發現judge卡在某一筆測資的情形,發現是在編譯的部份,經過分析code後發現下面的宣告

static char str[100000000000000];

大小為10^14 < 2^48,仍在48-bit VM理論能支援的大小內,但會導致g++編譯非常久。
2^32-1的array size在我的電腦上約花50秒,然而gcc、clang、clang++皆無此問題,應該是g++某些analysis phase導致的(但clang++似乎有bug,size超過32bit會overflow)
是否該對這類的code特別進行處理,或是編譯的部份也必須加上時間限制,否則可能導致DoS?

@morris821028
Copy link
Member

是的,後期都會在運行腳本中 (judge.py),加入 timeout <seconds> <commands>,先前遇過的是巨集展開造成編譯無法停止,這部分待商榷。

if os.system(T % 'timeout 10 gcc -std=c99 -O2 a.c -lm') != 0: break

@morris821028
Copy link
Member

能否給份完整的代碼、編譯參數和環境?

@jaidTw
Copy link
Author

jaidTw commented May 2, 2018

環境是在Arch Linux(kernel 4.16.5)下,gcc 7.3.1
編譯參數為

$ g++ -std=c++14 -O2 a.cpp -lm

code只要單純宣告過大的陣列且有顯式初始化(發issue時漏了這點)就會造成g++編譯過久,測試過static或auto都一樣,且測試過g++ 5.5.0也相同

int main() {
    static char str[100000000000000] = {};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants