(core) Fix issue with lodash's map interpreting objects with length as array-like

Summary:
Here's a series of badness that easily leads to a crash, in reverse order:
- Lodash's map() function interprets an object with a .length property as an array.
- Some very old code generated human-friendly descriptions of user actions,
  applying map() to parts of them. It so happens that this generated description
  isn't even used.
- If a user action is encountered with a sufficiently large length propery,
  map() would exhaust the server memory.

Fixed by removing old unneeded code, and replacing some other occurrences of
lodash's map() with native equivalents.

Test Plan: Tested manually on a local reproduction of the issue.

Reviewers: paulfitz

Reviewed By: paulfitz

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3938
This commit is contained in:
Dmitry S
2023-07-01 14:31:21 -04:00
parent b0aa17c932
commit 2b581ab7dc
6 changed files with 16 additions and 119 deletions

View File

@@ -8,7 +8,6 @@ import {safeJsonParse} from 'app/common/gutil';
import type {TableData} from 'app/common/TableData';
import {tsvEncode} from 'app/common/tsvFormat';
import {dom} from 'grainjs';
import map = require('lodash/map');
import zipObject = require('lodash/zipObject');
const G = getBrowserGlobals('document', 'DOMParser');
@@ -134,8 +133,11 @@ export function parsePasteHtml(data: string): RichPasteObject[][] {
}
// Helper function to add css style properties to an html tag
function _styleAttr(style: object) {
return map(style, (value, prop) => `${prop}: ${value};`).join(' ');
function _styleAttr(style: object|undefined) {
if (typeof style !== 'object') {
return '';
}
return Object.entries(style).map(([prop, value]) => `${prop}: ${value};`).join(' ');
}
/**