Skip to content

Commit 9219fd3

Browse files
committed
increase render size limits on *unlisted* public shares
1 parent 20e5d27 commit 9219fd3

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/packages/next/lib/share/get-contents.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,34 @@ import { getExtension } from "./util";
1212

1313
const MB: number = 1000000;
1414

15-
const LIMITS = {
15+
const LISTED_LIMITS = {
1616
listing: 3000, // directory listing is truncated after this many files
1717
ipynb: 7 * MB,
1818
sagews: 5 * MB,
1919
whiteboard: 3 * MB,
2020
slides: 3 * MB,
2121
other: 1 * MB,
22+
html: 3 * MB,
2223
// no special viewer
2324
generic: 2 * MB,
2425
};
2526

27+
const UNLISTED_LIMITS = {
28+
...LISTED_LIMITS,
29+
ipynb: 15 * MB,
30+
sagews: 10 * MB,
31+
whiteboard: 10 * MB,
32+
slides: 10 * MB,
33+
other: 5 * MB,
34+
html: 40 * MB, // E.g., cambridge: https://cocalc.com/Cambridge/S002211202200903X/S002211202200903X-Figure-4/files/Figure4.html
35+
36+
// no special viewer
37+
generic: 10 * MB,
38+
};
39+
2640
// also used for proxied content -- see https://github.com/sagemathinc/cocalc/issues/8020
27-
export function getSizeLimit(path: string): number {
41+
export function getSizeLimit(path: string, unlisted: boolean = false): number {
42+
const LIMITS = unlisted ? UNLISTED_LIMITS : LISTED_LIMITS;
2843
const ext = getExtension(path);
2944
if (hasSpecialViewer(ext)) {
3045
return LIMITS[ext] ?? LIMITS.other;
@@ -53,6 +68,7 @@ export interface PathContents {
5368
export default async function getContents(
5469
project_id: string,
5570
path: string,
71+
unlisted?: boolean, // if true, higher size limits, since much less likely to be abused
5672
): Promise<PathContents> {
5773
const fsPath = pathToFiles(project_id, path);
5874
const obj: PathContents = {};
@@ -70,7 +86,7 @@ export default async function getContents(
7086
}
7187
} else {
7288
// get actual file content
73-
if (stats.size >= getSizeLimit(fsPath)) {
89+
if (stats.size >= getSizeLimit(fsPath, unlisted)) {
7490
obj.truncated = "File too big to be displayed; download it instead.";
7591
} else {
7692
obj.content = (await fs.readFile(fsPath)).toString();
@@ -107,8 +123,8 @@ async function getDirectoryListing(
107123
obj.error = err;
108124
}
109125
listing.push(obj);
110-
if (listing.length >= LIMITS.listing) {
111-
truncated = `Too many files -- only showing ${LIMITS.listing} of them.`;
126+
if (listing.length >= LISTED_LIMITS.listing) {
127+
truncated = `Too many files -- only showing ${LISTED_LIMITS.listing} of them.`;
112128
break;
113129
}
114130
}

src/packages/next/lib/share/get-public-path-info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default async function getPublicPathInfo({
115115
contents: await getContents(
116116
rows[0].project_id,
117117
join(rows[0].path, relativePath),
118+
rows[0].unlisted,
118119
),
119120
projectTitle: title,
120121
projectAvatarImage: avatar_image_full,

0 commit comments

Comments
 (0)