拒绝服务攻击是一种滥用资源性的攻击。从程序源代码角度讲,对涉及到系统资源的外部数据应该进行严格校验,防止无限制的输入。
static final int MAX= 0x3200000; // 50MB// ...// write the files to the disk, but only if file is not insanely bigif (file.length > MAX) {throw new IllegalStateException("File is huge.");}FileOutputStream fos = new FileOutputStream(file_name);bop = new BufferedOutputStream(fos, SIZE);while ((count = fileInputStream.read(bytes)) != -1) {bop.write(bytes, 0, count);}
