Uploaded image for project: 'Commons Codec'
  1. Commons Codec
  2. CODEC-323

Possible Out-of-Memory problem in Apache Commons Codec PhoneticEngine class

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.17.0
    • None

    Description

      In the constructor of Apache Commons Codec PhoneticEngine class, the last parameter maxPhonemes accepts any integer. Although a negative or zero maxPhonemes value is rejected in a later stage, a very large integer still passes the checking. The maxPhonemes variable is used later in the apply() method to create a LinkedHashSet object, passing by the invoke() method in the PhoneticBuilder object stored in the PhoneticEngine object. By Java settings, the creation of LinkedHashSet objects won’t allocate all memory immediately. It will allocate a small amount of memory and when more memory is needed, the resize() method is called to request more memory. Thus creating the LinkedHashSet object with a large integer size will not result in errors immediately. When the logic tries adding items to the created LinkedHashSet object, it will first check if the number of elements in the set is larger than the provided maxPhonemes. The new element will be added to the set if and only if the current size of the set is smaller than the maxPhonemes. Thus if a very large maxPhonemes is provided, a large amount of new data could be added to the set. It could easily use up the memory because new elements could be added to the set. This causes a possible out-of-memory problem.

      Attachments

        Activity

          People

            Unassigned Unassigned
            arthur.chan Sheung Chi Chan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: