GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HttpUtil.getContentLength can throw parse error even when default value is supplied · Issue #12113 · netty/netty

HttpUtil.getContentLength can throw parse error even when default value is supplied #12113

New issue
Copy link
New issue
Copy link
Closed
#12114
Closed
HttpUtil.getContentLength can throw parse error even when default value is supplied#12113
#12114
Copy link
Milestone
4.1.75.Final

Description

@yawkat
yawkat
opened on Feb 18, 2022
Issue body actions

Fairly straight-forward to fix, but not sure if we should actually change the behavior or just change the javadoc. I can contribute a PR.

Expected behavior

Calling HttpUtil.getContentLength(HttpMessage, int) should return the default value when the header is not a number, in accordance with the javadoc:

Returns: the content length or defaultValue if this message does not have the "Content-Length" header or its value is not a number. Not to exceed the boundaries of integer.

Actual behavior

For invalid inputs, the method throws an exception:

Exception in thread "main" java.lang.NumberFormatException: For input string: "foo"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Long.parseLong(Long.java:711)
	at java.base/java.lang.Long.parseLong(Long.java:836)
	at io.netty.handler.codec.http.HttpUtil.getContentLength(HttpUtil.java:181)
	at io.netty.handler.codec.http.HttpUtil.getContentLength(HttpUtil.java:203)
	at io.micronaut.http.server.netty.fuzzing.X.main(X.java:12)

Steps to reproduce

Run the reproducer code.

Minimal yet complete reproducer code (or URL to code)

package io.micronaut.http.server.netty.fuzzing;

import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;

public class X {
    public static void main(String[] args) {
        DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        request.headers().add("Content-Length", "foo");
        System.out.println(HttpUtil.getContentLength(request, 0));
    }
}

Netty version

4.1.73.Final

JVM version (e.g. java -version)

openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

OS version (e.g. uname -a)

Linux yawkat-oracle 5.13.0-28-generic #31-Ubuntu SMP Thu Jan 13 17:41:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. normanmaurer commented on Feb 18, 2022

    @normanmaurer
    normanmaurer
    on Feb 18, 2022
    Member
    More actions

    I think we should fix the code... Let me do it.

    Reacted by Jonas Konrad
  2. normanmaurer commented on Feb 18, 2022

    @normanmaurer
    normanmaurer
    on Feb 18, 2022
    Member
    More actions

    @yawkat actually let me fix the javadocs so its consistent with the one that takes a long

  3. normanmaurer
    added a commit that references this issue on Feb 18, 2022

    Correct javadocs of HttpUtil

    936d3e1
  4. normanmaurer commented on Feb 18, 2022

    @normanmaurer
    normanmaurer
    on Feb 18, 2022
    Member
    More actions

    @yawkat #12114 PTAL

  5. normanmaurer
    added this to the 4.1.75.Final milestone on Feb 18, 2022
  6. yawkat commented on Feb 18, 2022

    @yawkat
    yawkat
    on Feb 18, 2022
    ContributorAuthor
    More actions

    Looks good

    The out-of-range behavior is still not fully described (Int.MAX_VALUE to Long.MAX_VALUE will clamp, but >Long.MAX_VALUE will throw NFE), but that would make the docs overly complicated and isn't relevant in the real world imo

  7. normanmaurer commented on Feb 18, 2022

    @normanmaurer
    normanmaurer
    on Feb 18, 2022
    Member
    More actions

    yeah I think we should keep it simple

  8. normanmaurer
    closed this as completedin #12114on Feb 21, 2022
  9. normanmaurer
    added 2 commits that reference this issue on Feb 21, 2022

    Correct javadocs of HttpUtil (#12114)

    ec0fc8f

    Correct javadocs of HttpUtil (#12114)

    aec4697
  10. raidyue
    added a commit that references this issue on Jul 8, 2022

    Correct javadocs of HttpUtil (netty#12114)

    acfcdb4
  11. franz1981
    added 2 commits that reference this issue on Aug 22, 2022

    Correct javadocs of HttpUtil (netty#12114)

    8b65774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.75.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.