fix: reject oversized checkout diffs (#2488)

* fix: reject oversized checkout diffs

* fix(diff): keep large previews from disconnecting clients

The physical socket limit is an OOM backstop, not a frame-size contract. Bound structured diff construction incrementally and report oversized previews without closing the client's socket.

* fix(app): preserve oversized diff state

* fix(diff): stay within relay frame limit

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
nikuscs
2026-07-30 00:48:05 +08:00
committed by GitHub
co-authored by Mohamed Boudra
parent 16bbead5a4
commit 9e5accee3c
24 changed files with 321 additions and 81 deletions
+8
View File
@@ -119,6 +119,7 @@ import {
type InlineReviewActions,
} from "@/review";
import { usePublishWorkingDiffAttachment, useWorkingDiff } from "@/git/use-working-diff";
import { DiffTooLargeState } from "@/git/diff-too-large-state";
export type { GitActionId, GitAction, GitActions } from "@/git/policy";
@@ -1755,6 +1756,7 @@ interface DiffBodyContentProps {
notGit: boolean;
isDiffLoading: boolean;
diffErrorMessage: string | null;
diffTooLarge: boolean;
hasChanges: boolean;
emptyMessage: string;
children: ReactElement;
@@ -1768,6 +1770,7 @@ function DiffBodyContent({
notGit,
isDiffLoading,
diffErrorMessage,
diffTooLarge,
hasChanges,
emptyMessage,
children,
@@ -1803,6 +1806,9 @@ function DiffBodyContent({
</View>
);
}
if (diffTooLarge) {
return <DiffTooLargeState />;
}
if (diffErrorMessage) {
return (
<View style={styles.errorContainer}>
@@ -2693,6 +2699,7 @@ export function GitDiffPane({
selectBase: handleSelectBase,
files,
diffPayloadError,
diffTooLarge,
isDiffLoading,
reviewActions,
reviewAttachment,
@@ -2855,6 +2862,7 @@ export function GitDiffPane({
notGit={notGit}
isDiffLoading={isDiffLoading}
diffErrorMessage={diffErrorMessage}
diffTooLarge={diffTooLarge}
hasChanges={hasChanges}
emptyMessage={emptyMessage}
checkingRepositoryLabel={t("workspace.git.diff.checkingRepository")}
@@ -0,0 +1,49 @@
import { useTranslation } from "react-i18next";
import { Text, View } from "react-native";
import { FileWarning } from "lucide-react-native";
import { StyleSheet, withUnistyles } from "react-native-unistyles";
import { ICON_SIZE, type Theme } from "@/styles/theme";
const ThemedFileWarning = withUnistyles(FileWarning);
const foregroundMutedIconColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
export function DiffTooLargeState() {
const { t } = useTranslation();
return (
<View style={styles.container} testID="diff-too-large">
<ThemedFileWarning size={ICON_SIZE.lg} uniProps={foregroundMutedIconColorMapping} />
<View style={styles.copy}>
<Text style={styles.title}>{t("workspace.git.diff.previewTooLargeTitle")}</Text>
<Text style={styles.description}>{t("workspace.git.diff.previewTooLargeDescription")}</Text>
</View>
</View>
);
}
const styles = StyleSheet.create((theme) => ({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
gap: theme.spacing[3],
paddingHorizontal: theme.spacing[6],
paddingTop: theme.spacing[16],
},
copy: {
alignItems: "center",
gap: theme.spacing[1],
maxWidth: 360,
},
title: {
color: theme.colors.foreground,
fontSize: theme.fontSize.base,
fontWeight: theme.fontWeight.normal,
textAlign: "center",
},
description: {
color: theme.colors.foregroundMuted,
fontSize: theme.fontSize.xs,
textAlign: "center",
},
}));
+1
View File
@@ -92,6 +92,7 @@ export function useCheckoutDiffQuery({
return {
files: payload?.files ?? [],
payloadError,
diffTooLarge: payload?.diffTooLarge === true,
isLoading: payload === null && enabled && isConnected,
isFetching: false,
isError: Boolean(payloadError),
+2
View File
@@ -79,6 +79,7 @@ export function useWorkingDiff({
const {
files,
payloadError: diffPayloadError,
diffTooLarge,
isLoading: isDiffLoading,
} = useCheckoutDiffQuery({
serverId,
@@ -123,6 +124,7 @@ export function useWorkingDiff({
selectBase,
files,
diffPayloadError,
diffTooLarge,
isDiffLoading,
reviewActions,
reviewAttachment,