From owner-svn-src-all@freebsd.org Sun Jan 6 23:59:05 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3F162149F840; Sun, 6 Jan 2019 23:59:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D95B597265; Sun, 6 Jan 2019 23:59:04 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CC46A7AFB; Sun, 6 Jan 2019 23:59:04 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x06Nx4Wb096420; Sun, 6 Jan 2019 23:59:04 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x06Nx4ib096419; Sun, 6 Jan 2019 23:59:04 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201901062359.x06Nx4ib096419@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 6 Jan 2019 23:59:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342823 - head/contrib/xz/src/common X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/contrib/xz/src/common X-SVN-Commit-Revision: 342823 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: D95B597265 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.98)[-0.978,0]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jan 2019 23:59:05 -0000 Author: kib Date: Sun Jan 6 23:59:04 2019 New Revision: 342823 URL: https://svnweb.freebsd.org/changeset/base/342823 Log: Clamp tuklib_physmem() return value to SIZE_T_MAX. On 32bit platforms it is possible to have (much) more physical RAM than is mappable into single address space. In this case liblzma scales the value into a request to mmap more address space than it is theoretically possible. Reported and tested by: pho Reviewed by: delphij Discussed with: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/contrib/xz/src/common/tuklib_physmem.c Modified: head/contrib/xz/src/common/tuklib_physmem.c ============================================================================== --- head/contrib/xz/src/common/tuklib_physmem.c Sun Jan 6 23:43:12 2019 (r342822) +++ head/contrib/xz/src/common/tuklib_physmem.c Sun Jan 6 23:59:04 2019 (r342823) @@ -45,6 +45,7 @@ # include #elif defined(TUKLIB_PHYSMEM_SYSCONF) +# include # include #elif defined(TUKLIB_PHYSMEM_SYSCTL) @@ -145,13 +146,16 @@ tuklib_physmem(void) #elif defined(TUKLIB_PHYSMEM_SYSCONF) const long pagesize = sysconf(_SC_PAGESIZE); const long pages = sysconf(_SC_PHYS_PAGES); - if (pagesize != -1 && pages != -1) + if (pagesize != -1 && pages != -1) { // According to docs, pagesize * pages can overflow. // Simple case is 32-bit box with 4 GiB or more RAM, // which may report exactly 4 GiB of RAM, and "long" // being 32-bit will overflow. Casting to uint64_t // hopefully avoids overflows in the near future. ret = (uint64_t)pagesize * (uint64_t)pages; + if (ret > SIZE_T_MAX) + ret = SIZE_T_MAX; + } #elif defined(TUKLIB_PHYSMEM_SYSCTL) int name[2] = {