Skip to content
Snippets Groups Projects
Commit 0e56e4a7 authored by Stanislas Sobieski's avatar Stanislas Sobieski
Browse files

[FIX] cloc: avoid memory issue on big file


Before this commit:
Files that should be ignored in the manifest but aren't (js library for example)
it can happen that files have huge lines, the regex to substract the
comments will overuse memory.
For example, a file of 13M with a line of more that 8M characters, the
memory consumptions peak at 1.7G

The results might be different, but it's an acceptable compromise

closes odoo/odoo#119977

Signed-off-by: default avatarThibault Francois <tfr@odoo.com>
parent 06a8ecbf
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ DEFAULT_EXCLUDE = [
STANDARD_MODULES = ['web', 'web_enterprise', 'website_animate', 'base']
MAX_FILE_SIZE = 25 * 2**20 # 25 MB
MAX_LINE_SIZE = 100000
class Cloc(object):
def __init__(self):
......@@ -60,6 +61,10 @@ class Cloc(object):
# Based on https://stackoverflow.com/questions/241327
s = s.strip() + "\n"
total = s.count("\n")
# To avoid to use too much memory we don't try to count file
# with very large line, usually minified file
if max(len(l) for l in s.split('\n')) > MAX_LINE_SIZE:
return -1, "Max line size exceeded"
def replacer(match):
s = match.group(0)
return " " if s.startswith('/') else s
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment