Skip to content

Commit 9041b5d

Browse files
authored
Backport #32277 to 3.1 (#32482)
## Description Update guard logic to permit writing 0 length buffers. This can happen in certain globalized scenarios (ex. `¿` with Portugese) where the first char needs to be encoded. Patch #31299 for 3.1 by cherry-picking the #32277 squash commit. ## Customer Impact Writing 0-length char buffers leads to an ArgumentOutOfRangeException. This may occur in a globalization context with certain chars such as `¿`. #31299 (comment) Also impacts Orchard: #31299 (comment) ## Regression? - [ ] Yes - [x] No [If yes, specify the version the behavior has regressed from] ## Risk - [ ] High - [ ] Medium - [x] Low Low risk as we've just updated the logic slightly to permit 0 length buffers. ## Verification - [x] Manual (required) - [x] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A Addresses #31299
1 parent 18a6f0c commit 9041b5d

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

eng/common/tools.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
323323
}
324324

325325
$msbuildVersionDir = if ([int]$vsMajorVersion -lt 16) { "$vsMajorVersion.0" } else { "Current" }
326-
return $global:_MSBuildExe = Join-Path $vsInstallDir "MSBuild\$msbuildVersionDir\Bin\msbuild.exe"
326+
return $global:_MSBuildExe = Join-Path $vsInstallDir "MSBuild\$msbuildVersionDir\Bin\amd64\msbuild.exe"
327327
}
328328

329329
function InitializeVisualStudioEnvironmentVariables([string] $vsInstallDir, [string] $vsMajorVersion) {

src/Mvc/Mvc.ViewFeatures/src/Buffers/ViewBufferTextWriter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,21 @@ public override void Write(char[] buffer, int index, int count)
110110
throw new ArgumentNullException(nameof(buffer));
111111
}
112112

113-
if (index < 0 || index >= buffer.Length)
113+
if (index < 0)
114114
{
115115
throw new ArgumentOutOfRangeException(nameof(index));
116116
}
117117

118-
if (count < 0 || (buffer.Length - index < count))
118+
if (count < 0)
119119
{
120120
throw new ArgumentOutOfRangeException(nameof(count));
121121
}
122122

123+
if (buffer.Length - index < count)
124+
{
125+
throw new ArgumentOutOfRangeException(nameof(buffer.Length));
126+
}
127+
123128
Buffer.AppendHtml(new string(buffer, index, count));
124129
}
125130

@@ -326,4 +331,4 @@ public override async Task FlushAsync()
326331
await _inner.FlushAsync();
327332
}
328333
}
329-
}
334+
}

src/Mvc/Mvc.ViewFeatures/test/Buffers/ViewBufferTextWriterTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ public async Task WriteLines_WritesCharBuffer()
124124
Assert.Equal<object>(new[] { newLine, newLine }, actual);
125125
}
126126

127+
[Fact]
128+
public void Write_WritesEmptyCharBuffer()
129+
{
130+
// Arrange
131+
var buffer = new ViewBuffer(new TestViewBufferScope(), "some-name", pageSize: 4);
132+
var writer = new ViewBufferTextWriter(buffer, Encoding.UTF8);
133+
var charBuffer = new char[0];
134+
135+
// Act
136+
writer.Write(charBuffer, 0, 0);
137+
138+
// Assert
139+
var actual = GetValues(buffer);
140+
Assert.Equal<object>(new[] { string.Empty }, actual);
141+
}
142+
127143
[Fact]
128144
public async Task Write_WritesStringBuffer()
129145
{
@@ -170,4 +186,4 @@ public override string ToString()
170186
}
171187
}
172188
}
173-
}
189+
}

0 commit comments

Comments
 (0)