<html><head><meta content="width=device-width, initial-scale=1" name="viewport" /><style>
.sa-banner-container a:visited {
        color: #03315f;
}
@media screen and (max-width: 480px) {
        .sa-url-list-item {
                display: block !important;
                padding-bottom: 8px !important;
        }
        .sa-url-separator {
                display: none !important;
        }
        .sa-banner-container,
        .x_sa-banner-container {
                width: 100% !important;
                max-width: 100% !important;
        }
        .sa-attachment-list,
        .x_sa-attachment-list {
                width: 100% !important;
        }
        .sa-footer-item {
                display: block !important;
                padding-right: 0 !important;
                padding-bottom: 8px !important;
        }
}
</style></head><body>
<!--[if mso]>
<table cellpadding="0" cellspacing="0" border="0" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin-bottom: 20px;">
<tr>
<td style="padding: 0; mso-line-height-rule: exactly;">
<![endif]-->
<table id="sa-banner-347c6be4-a0ae-4336-aa63-42e57d2dc6f8" class="sa-banner-container" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin-bottom: 20px; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-family: 'Amazon Ember', Arial, sans-serif; mso-table-wrap: none; mso-margin-bottom-alt: 20px;">
<tr>
<td style="padding: 8px 16px; border: 1px solid #AAB7B8; border-radius: 2px; mso-line-height-rule: exactly; mso-padding-alt: 8px 16px;">
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin-bottom: 4px; mso-margin-bottom-alt: 4px;">
<tr>
<td style="padding: 0; font-size: 14px; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly; mso-font-width: 100%;">
Your attachments are now available for secure download. Amazon has replaced the attachments in this email with download links.
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin-bottom: 4px; mso-margin-bottom-alt: 4px;">
<tr>
<td style="padding: 0; font-size: 13px; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly; mso-font-width: 100%;">
<strong style="mso-bidi-font-weight: bold;">Important:</strong> These links may contain content that is confidential. Please exercise appropriate caution when sharing.
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin-top: 4px; margin-bottom: 8px; mso-margin-top-alt: 4px; mso-margin-bottom-alt: 8px;">
<tr>
<td style="padding: 0 0 4px 0; mso-padding-alt: 0 0 4px 0;">
<ul style="display: inline-block; margin: 0; padding: 0;">
<li style="display: inline-block; list-style-type: none; margin: 0;"><span style="display: inline-block; padding-right: 12px; font-weight: 600; font-size: 14px; font-family: 'Amazon Ember', Arial, sans-serif;">2 Attachments</span></li>
<li style="display: inline-block; list-style-type: none; margin: 0;"><span style="display: inline-block; padding-right: 12px; font-size: 14px; font-family: 'Amazon Ember', Arial, sans-serif;"><a href="https://us-west-2.secure-attach.amazon.com/all/347c6be4-a0ae-4336-aa63-42e57d2dc6f8/d96d2ca6-23f6-4cda-b5e2-db241a0038bc" style="color: #0073BB; text-decoration: none; mso-line-height-rule: exactly;">Download all</a></span></li>
<li style="display: inline-block; list-style-type: none; margin: 0;"><span style="font-size: 13px; color: #555; font-family: 'Amazon Ember', Arial, sans-serif; background-color: #D1F1FF; padding: 4px 8px; border-radius: 2px; mso-font-width: 100%;">
Passcode required <strong style="mso-bidi-font-weight: bold;">yJQfHY</strong>
</span>
</li>
</ul>
</td>
</tr>
<tr>
<td style="padding: 4px 0 0 0; mso-padding-alt: 4px 0 0 0;">
<table class="sa-attachment-list" cellpadding="0" cellspacing="0" border="0" style="width: 100%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt;">
<tr><td style="padding: 0; mso-line-height-rule: exactly;">
<ul style="display: inline-block; margin: 0; padding: 0; width: 100%;">
<li class="sa-url-list-item" style="display: inline-block; list-style-type: none; margin: 0;"><span style="display: inline-block; padding-right: 12px; padding-bottom: 8px;"><a href="https://us-west-2.secure-attach.amazon.com/d96d2ca6-23f6-4cda-b5e2-db241a0038bc/50e68313-b010-4fc5-bf58-be4858500d6c" style="color: #0073BB; text-decoration: none; font-size: 14px; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly; mso-font-width: 100%;" title="rep.c">rep.c</a></span></li>
<li class="sa-url-list-item" style="display: inline-block; list-style-type: none; margin: 0;"><span style="display: inline-block; padding-right: 12px; padding-bottom: 8px;"><a href="https://us-west-2.secure-attach.amazon.com/d96d2ca6-23f6-4cda-b5e2-db241a0038bc/0dee9fa4-1312-4bc1-ab9d-834606b9ef63" style="color: #0073BB; text-decoration: none; font-size: 14px; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly; mso-font-width: 100%;" title="upstream-report.md">upstream-report.md</a></span></li>
</ul>
</td></tr>
</table>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; margin-bottom: 8px; mso-margin-bottom-alt: 8px;">
<tr>
<td style="padding: 0; font-size: 13px; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly; mso-font-width: 100%;">Attachments Available Until: <strong style="mso-bidi-font-weight: bold;">December 09, 2026, 21:44 (UTC+00:00)</strong>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%%; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-top: 1px solid #E7E7E7; padding-top: 8px; mso-padding-alt: 8px 0 0 0;">
<tr>
<td style="padding: 0; font-size: 12px; mso-ansi-font-size: 12px; color: #555; font-family: 'Amazon Ember', Arial, sans-serif; mso-line-height-rule: exactly;">
<span class="sa-footer-item" style="display: inline-block; padding-right: 24px; padding-bottom: 4px; font-size: 12px; mso-ansi-font-size: 12px;">
Help us improve: 
<a href="https://amazonexteu.qualtrics.com/jfe/form/SV_ehuz6zGo8YnsRKK" style="color: #0073BB; text-decoration: none; font-size: 12px; mso-ansi-font-size: 12px; mso-line-height-rule: exactly;">
Share Your Feedback
</a>
</span>
<span class="sa-footer-item" style="display: inline-block; padding-bottom: 4px; font-size: 12px; mso-ansi-font-size: 12px;">
Visit 
<a href="https://docs.secure-attach.amazon.com/guide" style="color: #0073BB; text-decoration: none; font-size: 12px; mso-ansi-font-size: 12px; mso-line-height-rule: exactly;">
Here
</a> 
for FAQs and support resources.
</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
<p>Hello,

Found a bug in the stable branch of x265.

If the pts goes backwards (e.g. a timestamp discontinuity with VFR input),
the frame duration and therefore frame_size_maximum become negative.
Since d46938de the MinCR / buffer fill restriction in rate_estimate_qscale()
is applied after vbv_pass1() and is no longer followed by
X264_MAX( q0, q ) and the final qscale clipping, so the negative limit turns
q negative. The resulting NaN QP makes the row loops in
x264_ratecontrol_mb() spin forever when compiled with -ffast-math
(observed with clang 15, 18 and 20 on x86_64).

**Reproducer**

Attached `rep.c` (standalone, uses only libx264):

```
CC=clang-20 ./configure --disable-cli --enable-static --enable-pic --disable-opencl --disable-lavf
make libx264.a
gcc -O1 -I. rep.c libx264.a -lpthread -lm -ldl -o rep
./rep 1 0     # hangs (pts goes backwards)
./rep 0 0     # completes: "ok, 182 frames"
```

Results:

| Build | ./rep 1 0 (3 runs) |
|---|---|
| clang 18.1.3, d46938de~1 | ok ok ok |
| clang 18.1.3, d46938de | hang hang hang |
| clang 18.1.3, b35605ac (stable) | hang hang hang |
| clang 18.1.3, b35605ac + `--extra-cflags=-fno-finite-math-only` | ok ok ok |
| clang 20.1.2, d46938de~1 | ok ok ok |
| clang 20.1.2, d46938de | hang hang hang |
| clang 20.1.2, b35605ac (stable) | hang hang hang |
| clang 20.1.2, b35605ac + `--extra-cflags=-fno-finite-math-only` | ok ok ok |
| clang 20.1.2, master 0480cb05 | hang hang hang |
| clang 15.0.7, b35605ac | hang hang hang |
| GCC, b35605ac | ok ok ok |

**Backtrace (hung state)**

```
Thread (worker): x264_8_ratecontrol_mb <- slices_write <- threadpool_thread      [spinning]
Thread (worker): predict_row_size_to_end <- x264_8_ratecontrol_mb <- slices_write [spinning]
Thread (worker): x264_8_frame_cond_wait <- x264_8_macroblock_analyse <- slices_write
Thread (main):   x264_8_threadpool_wait <- encoder_frame_end <- x264_8_encoder_encode
```


---
 encoder/ratecontrol.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index a42305c5..2c3c45fa 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -2460,7 +2460,8 @@ static float rate_estimate_qscale( x264_t *h )
         if( rcc->b_vbv )
         {
             double frame_size_maximum = X264_MIN( rcc->frame_size_maximum, X264_MAX( rcc->buffer_fill, 0.001 ) );
-            if( rcc->frame_size_planned > frame_size_maximum )
+            /* frame_size_maximum can be negative if the frame duration is negative (pts going backwards). */
+            if( frame_size_maximum > 0 && rcc->frame_size_planned > frame_size_maximum )
             {
                 q *= rcc->frame_size_planned / frame_size_maximum;
                 rcc->frame_size_planned = frame_size_maximum;
@@ -2646,7 +2647,8 @@ static float rate_estimate_qscale( x264_t *h )
         if( rcc->b_vbv )
         {
             double frame_size_maximum = X264_MIN( rcc->frame_size_maximum, X264_MAX( rcc->buffer_fill, 0.001 ) );
-            if( rcc->frame_size_planned > frame_size_maximum )
+            /* frame_size_maximum can be negative if the frame duration is negative (pts going backwards). */
+            if( frame_size_maximum > 0 && rcc->frame_size_planned > frame_size_maximum )
             {
                 q *= rcc->frame_size_planned / frame_size_maximum;
                 rcc->frame_size_planned = frame_size_maximum;
-- 
2.43.0

</body></html>