Skip to content

Commit 1b91ec8

Browse files
author
ArthurHub
committed
fix posible endless loop in CorrectRelativeUrls
1 parent b1731f5 commit 1b91ec8

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎Source/HtmlRenderer/Core/Handlers/StylesheetLoadHandler.cs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ private static string LoadStylesheetFromUri(HtmlContainerInt htmlContainer, Uri
153153
private static string CorrectRelativeUrls(string stylesheet, Uri baseUri)
154154
{
155155
int idx = 0;
156-
while (idx != -1 && idx < stylesheet.Length)
156+
while (idx >= 0 && idx < stylesheet.Length)
157157
{
158158
idx = stylesheet.IndexOf("url", idx, StringComparison.OrdinalIgnoreCase);
159-
if (idx > 0)
159+
if (idx >= 0)
160160
{
161-
int endIdx = stylesheet.IndexOf(")", idx, StringComparison.OrdinalIgnoreCase);
162-
if (endIdx > 0)
161+
int endIdx = stylesheet.IndexOf(')', idx);
162+
if (endIdx > idx + 4)
163163
{
164164
var offset1 = 4 + (stylesheet[idx + 4] == '\'' ? 1 : 0);
165165
var offset2 = (stylesheet[endIdx - 1] == '\'' ? 1 : 0);
@@ -170,12 +170,12 @@ private static string CorrectRelativeUrls(string stylesheet, Uri baseUri)
170170
url = new Uri(baseUri, url);
171171
stylesheet = stylesheet.Remove(idx + 4, endIdx - idx - 4);
172172
stylesheet = stylesheet.Insert(idx + 4, url.AbsoluteUri);
173-
idx += url.AbsoluteUri.Length + 4;
174-
}
175-
else
176-
{
177-
idx = endIdx + 1;
178173
}
174+
idx = endIdx + 1;
175+
}
176+
else
177+
{
178+
idx += 4;
179179
}
180180
}
181181
}

0 commit comments

Comments
 (0)