Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 103021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:03:28+00:00 2026-05-11T01:03:28+00:00

I am writing a web server application in C# and using StreamReader class to

  • 0

I am writing a web server application in C# and using StreamReader class to read from an underlying NetworkStream:

 NetworkStream ns = new NetworkStream(clientSocket);  StreamReader sr = new StreamReader(ns);  String request = sr.ReadLine(); 

This code is prone to DoS attacks because if the attacker never disconnects we will never finish reading the line. Is there any way to limit the number of characters read by StreamReader.ReadLine() in .NET?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:03:28+00:00Added an answer on May 11, 2026 at 1:03 am

    You would have to use the Read(char[], int, int) overload (which does limit the length) and do your own end-of-line detection; shouldn’t be too tricky.

    For a slightly lazy version (that uses the single-characted reading version):

    static IEnumerable<string> ReadLines(string path, int maxLineLength) {     StringBuilder currentLine = new StringBuilder(maxLineLength);     using (var reader = File.OpenText(path))     {         int i;         while((i = reader.Read()) > 0) {             char c = (char) i;             if(c == '\r' || c == '\n') {                 yield return currentLine.ToString();                 currentLine.Length = 0;                 continue;             }             currentLine.Append((char)c);             if (currentLine.Length > maxLineLength)             {                 throw new InvalidOperationException('Max length exceeded');             }         }         if (currentLine.Length > 0)         {             yield return currentLine.ToString();         }                     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Resolved by removing the RefreshReport: CustomerReport1.SetParameterValue('CustomerID', txtCustID.Text) CrystalReportViewer1.ReportSource = CustomerReport1 May 11, 2026 at 11:48 am
  • added an answer Take a look here: http://www.sqlite.org/cvstrac/wiki?p=ManagementTools Base SQLiteStudio SQLiteManager SyBrowser May 11, 2026 at 11:48 am
  • added an answer glGenerateMipmapOES(GL_TEXTURE_2D); document http://www.khronos.org/opengles/sdk/docs/man/glGenerateMipmap.xml May 11, 2026 at 11:48 am

Related Questions

I am writing a web server application in C# and using StreamReader class to
I am writing a web server in Java and I want it to support
I am writing a web application that requires user interaction via email. I'm curious
I am writing a web app using TurboGears, and in that app the users
I am writing a web application that will run in kiosk mode on a
I am writing a web-framework for Python, of which the goal is to be
I am writing a web application that works with exchange, and so needs to
I am writing a web service in Java, and I am trying to figure
I am writing a web application using PHP. I want to use the MVC
I am writing a web app in PHP, and it has come time to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.