Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
/** Assuming the heap size as 512 MB (calculated as 1/4th of 2 GB RAM = 512 MB)
 *  Considering long values being entered (64 bits each, the max number of elements
 *  would be 512 MB/64bits = 67108864)
 */
public class ShowHeapError {
  Vector<Long> names = new Vector<Long>(); // Accepts unknown number of records
  long newID = 0L;
  int count = 67108865;
  int i = 0;
  InputStreamReader input = new InputStreamReader(System.in);
  Scanner reader = new Scanner(input);

  public void addNames() {
    try {
      do {
        // Adding unknown number of records to a list
        // The user can enter more IDs than the heap can support and thusas a result,
        // exhaust the heap. Assume that the record ID is a 64 bit long value

        System.out.print("Enter recordID (To quit, enter -1): ");
        newID = reader.nextLong();

        names.addElement(newID);
        i++;
      } while (i < count || newID != -1);
    } finally {
      input.close();
    }
  }

  public static void main(String[] args) {
    ShowHeapError demo = new ShowHeapError();
    demo.addNames();
  }
}

...

CERT C Secure Coding Standard

MEM11-C. Do not assume infinite heap space

CERT C++ Secure Coding Standard

MEM12-CPP. Do not assume infinite heap space

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b45514c3c430ea3e-142f91fc-4d7a4279-831c86df-0bfacb746ef4dbd5a3b1bae5"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

"Resource Exhaustion [XZP]"

]]></ac:plain-text-body></ac:structured-macro>

MITRE CWE

CWE ID 400, "Uncontrolled Resource Consumption ('Resource Exhaustion')"

 

CWE ID 770, "Allocation of Resources Without Limits or Throttling"

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eece3a51e4056afa-e1d4f8e0-4a234098-9dbcb4c4-04b152dd70ae3662220950e0"><ac:plain-text-body><![CDATA[

[[Sun 2006

AA. Bibliography#Sun 06]]

[Garbage Collection Ergonomics

http://java.sun.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html ], "Default values for the Initial and Maximum heap size"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="793f987a8d60b532-549720c0-4b5c4c2a-8a53b8df-fa38bb25d2637e4ccee572f9"><ac:plain-text-body><![CDATA[

[[Java 2006

AA. Bibliography#Java 06]]

[java - the Java application launcher

http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html ], "Syntax for increasing the heap size"

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0717058cee3a93a7-4548d4c6-485e4824-a585a4e2-f9a869357e2badb247729251"><ac:plain-text-body><![CDATA[

[[Sun 2003

AA. Bibliography#Sun 03]]

Chapter 5: Tuning the Java Runtime System, [Tuning the Java Heap

http://docs.sun.com/source/817-2180-10/pt_chap5.html#wp57027]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="653685c9d5a721c8-ffc7f001-48e94535-a181b69a-0ee8effee053470f413d8779"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class ObjectInputStream and ObjectOutputStream

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ad4cd8a6dd34ef2b-af07a7c9-4ec642b2-81819a54-0f2b6b2951a35b56799dfbe6"><ac:plain-text-body><![CDATA[

[[SDN 2008

AA. Bibliography#SDN 08]]

[Serialization FAQ

http://java.sun.com/javase/technologies/core/basic/serializationFAQ.jsp]

]]></ac:plain-text-body></ac:structured-macro>

...