From dev-return-336692-archive-asf-public=cust-asf.ponee.io@lucene.apache.org Thu Oct 18 12:00:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0A9F9180674 for ; Thu, 18 Oct 2018 12:00:04 +0200 (CEST) Received: (qmail 22036 invoked by uid 500); 18 Oct 2018 10:00:03 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 22026 invoked by uid 99); 18 Oct 2018 10:00:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Oct 2018 10:00:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 5BED11A0868 for ; Thu, 18 Oct 2018 10:00:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.301 X-Spam-Level: X-Spam-Status: No, score=-110.301 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id gYSVVjOqwOkz for ; Thu, 18 Oct 2018 10:00:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id F2F7C5F36D for ; Thu, 18 Oct 2018 10:00:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 34D31E262F for ; Thu, 18 Oct 2018 10:00:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id A7C4A2125E for ; Thu, 18 Oct 2018 10:00:00 +0000 (UTC) Date: Thu, 18 Oct 2018 10:00:00 +0000 (UTC) From: "Vladimir Dolzhenko (JIRA)" To: dev@lucene.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (LUCENE-8533) Incorrect readVInt: negative number could be returned MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LUCENE-8533?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Vladimir Dolzhenko updated LUCENE-8533: --------------------------------------- Attachment: LUCENE-8533_fix_readVInt_javadoc.patch > Incorrect readVInt: negative number could be returned > ----------------------------------------------------- > > Key: LUCENE-8533 > URL: https://issues.apache.org/jira/browse/LUCENE-8533 > Project: Lucene - Core > Issue Type: Improvement > Reporter: Vladimir Dolzhenko > Assignee: Uwe Schindler > Priority: Major > Attachments: LUCENE-8533_fix_readVInt_javadoc.patch, readVInt.patch > > > {{readVInt()}} has to return positive numbers (and zero), throw some exception in case of negative numbers. > While for the sequence of bytes {{[-1, -1, -1, -1, 15]}} it returns {{-1}}. > simplifying [readVInt|https://github.com/apache/lucene-solr/blob/1d85cd783863f75cea133fb9c452302214165a4d/lucene/core/src/java/org/apache/lucene/store/DataInput.java#L113] up to last readByte (exclusive): > {code:java} > int i = ((byte)-1) & 0x7F; > i |= (((byte)-1) & 0x7F) << 7; > i |= (((byte)-1) & 0x7F) << 14; > i |= (((byte)-1) & 0x7F) << 21; > {code} > Here {{i = 268435455}} or in binary format is {{00001111_11111111_11111111_11111111}} > Keeping in mind that {{int}} is a signed type we have only 3 more bits before overflow happens or in another words {{(Integer.MAX_VALUE - i) >> 28 == 7}} - that's max value could be stored in 5th byte to avoid overflow. > Instead of > {code:java} > i |= (b & 0x0F) << 28; > if ((b & 0xF0) == 0) return i; > {code} > has to be > {code:java} > i |= (b & 0x07) << 28; > if ((b & 0xF8) == 0) return i; > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org