--- ../subversion-nightly-r1425714.org/subversion/libsvn_diff/diff_file.c	2012-12-25 06:07:43.000000000 +0900
+++ subversion/libsvn_diff/diff_file.c	2012-12-27 00:59:26.000000000 +0900
@@ -122,7 +122,8 @@
  * whatsoever.  If there is a number someone comes up with that has some
  * argumentation, let's use that.
  */
-/* If you change this number, update test_wrap() in diff-diff3-test.c */
+/* If you change this number, update test_wrap() and test_identical_suffix()
+   in diff-diff3-test.c */
 #define CHUNK_SHIFT 17
 #define CHUNK_SIZE (1 << CHUNK_SHIFT)
 
@@ -497,6 +498,7 @@
  * The number 50 is more or less arbitrary, based on some real-world tests
  * with big files (and then doubling the required number to be on the safe
  * side). This has a negligible effect on the power of the optimization. */
+/* If you change this number, update test_identical_suffix() in diff-diff3-test.c */
 #ifndef SUFFIX_LINES_TO_KEEP
 #define SUFFIX_LINES_TO_KEEP 50
 #endif
@@ -838,8 +840,10 @@
   /* Stop when we encounter the identical suffix. If suffix scanning was not
    * performed, suffix_start_chunk will be -1, so this condition will never
    * be true. */
-  if (file->chunk == file->suffix_start_chunk
-      && curp - file->buffer == file->suffix_offset_in_chunk)
+  if ((file->chunk == file->suffix_start_chunk
+       && curp - file->buffer == file->suffix_offset_in_chunk)
+      || (file->chunk + 1 == file->suffix_start_chunk
+          && curp == endp && file->suffix_offset_in_chunk == 0))
     return SVN_NO_ERROR;
 
   /* Allocate a new token, or fetch one from the "reusable tokens" list. */
--- ../subversion-nightly-r1425714.org/subversion/tests/libsvn_diff/diff-diff3-test.c	2012-07-03 05:13:51.000000000 +0900
+++ subversion/tests/libsvn_diff/diff-diff3-test.c	2012-12-27 00:53:51.000000000 +0900
@@ -2429,6 +2429,73 @@
   return SVN_NO_ERROR;
 }
 
+/* In the past, when identical suffix started at a chunk boundary,
+   incorrect diff was generated.
+ */
+#define ORIGINAL_CONTENTS_PATTERN "0123456789abcde\n"
+#define INSERTED_LINE "0123456789ABCDE\n"
+#define LINE_LENGTH 16
+#define CHUNK_SIZE (1 << 17)
+#define SUFFIX_LINES_TO_KEEP 50
+static svn_error_t *
+test_identical_suffix(apr_pool_t *pool)
+{
+  char original_contents[CHUNK_SIZE + 1024 + 1];
+  char modified_contents[sizeof(original_contents) + LINE_LENGTH * 2];
+  apr_size_t i;
+
+  for (i = 0; i < sizeof(original_contents) - 1; i += LINE_LENGTH)
+    {
+      strcpy(&original_contents[i], ORIGINAL_CONTENTS_PATTERN);
+    }
+
+  for (i = 0; i < sizeof(modified_contents) - 1; i += LINE_LENGTH)
+    {
+      strcpy(&modified_contents[i], ORIGINAL_CONTENTS_PATTERN);
+    }
+  memcpy(&modified_contents[1024], INSERTED_LINE, LINE_LENGTH);
+  memcpy(&modified_contents[CHUNK_SIZE - LINE_LENGTH
+                                         * (SUFFIX_LINES_TO_KEEP + 1)],
+         INSERTED_LINE, LINE_LENGTH);
+
+  SVN_ERR(two_way_diff("identical-suffix-original",
+                       "identical-suffix-modified",
+                       original_contents, modified_contents,
+                       apr_psprintf(pool,
+                                    "--- identical-suffix-original" NL
+                                    "+++ identical-suffix-modified" NL
+                                    "@@ -%d,6 +%d,7 @@" NL
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    "+" INSERTED_LINE
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    "@@ -%d,6 +%d,7 @@" NL
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    "+" INSERTED_LINE
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN
+                                    " " ORIGINAL_CONTENTS_PATTERN,
+                                    1 + 1024 / LINE_LENGTH - 3,
+                                    1 + 1024 / LINE_LENGTH - 3,
+                                    1 + CHUNK_SIZE / LINE_LENGTH
+                                    - SUFFIX_LINES_TO_KEEP - 1 - 3 - 1,
+                                    1 + CHUNK_SIZE / LINE_LENGTH
+                                    - SUFFIX_LINES_TO_KEEP - 1 - 3),
+                       NULL, pool));
+
+  return SVN_NO_ERROR;
+}
+#undef ORIGINAL_CONTENTS_PATTERN
+#undef INSERTED_LINE
+#undef LINE_LEGTH
+#undef CHUNK_SIZE
+#undef SUFFIX_LINES_TO_KEEP
+
 /* ========================================================================== */
 
 struct svn_test_descriptor_t test_funcs[] =
@@ -2460,5 +2527,7 @@
                    "4-way merge; see variance-adjusted-patching.html"),
     SVN_TEST_XFAIL2(test_wrap,
                    "difference at the start of a 128KB window"),
+    SVN_TEST_PASS2(test_identical_suffix,
+                   "identical suffix starts at the boundary of a chunk"),
     SVN_TEST_NULL
   };
